aspose file tools*
The moose likes Beginning Java and the fly likes Complex Number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Complex Number" Watch "Complex Number" New topic
Author

Complex Number

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Hello
How I can correct take input from the user in Complex Class?
for example the user has to input 2.3i + 4.7

Thanks
Kris Nelson
Ranch Hand

Joined: Nov 04, 2001
Posts: 35
Not sure how your Complex class is implemented or how the input is obtained (console, param, textfield, etc.) but if "2.3i + 4.7" is read in as a String, you could try using the String.indexOf(String) method to find the index of the "i" and the "+" ( or of "i + " ) and create substrings of "2.3" and "4.7" two convert into floats or doubles, depending what is needed.
Does this help?

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com


WebNelly.com<br />Java/XML Web Development<br />Check it out!<br /><a href="http://www.webnelly.com" target="_blank" rel="nofollow">http://www.webnelly.com</a>
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
I need to read c(complex number) c= -0.2 + 0.8i ..
What I has to use for it? How user can enter two numbers??
Thanks a lot
Kris Nelson
Ranch Hand

Joined: Nov 04, 2001
Posts: 35
Where will you be reading the complex number from:
* the console,
* a file,
* a textfield,
* command line argument
* an applet parameter,
* or somewhere else?
You can read a line of text (into a String) from any of these places. Processing the String will be the same, obtaining the String depends on where you get it from.

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
from Command Line
Kris Nelson
Ranch Hand

Joined: Nov 04, 2001
Posts: 35
If it's from the command line like this:
java MyComplexProgram 2.3i+4.7
then args[0] in the main method will be the String:
2.3i+4.7
Do you know how to use the String.indexOf() method to find the indecies of the 'i' and the '+' and how to use the String.substring() method with those indecies to get the String values of "2.3" and "4.7"?
If not, check the javadoc for the String class. It's better to read up on it yourself than have someone in a forum tell you.

------------------
WebNelly.com
Java/XML Web Development
Check it out!
http://www.webnelly.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complex Number
 
Similar Threads
Swing - Problem with JProgress indefenite state
Converting/reformatting data from text file(with delimiters)
How to hide servlet path?
WA #1.....word association
Update a program input after running