This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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<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>
Joined: May 26, 2001
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
Joined: Nov 04, 2001
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.
If it's from the command line like this: java MyComplexProgram 2.3i+4.7 then args 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.