• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Complex Number

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Shn
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from Command Line
 
Kris Nelson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic