• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking void method  RSS feed

 
Joshua Corcoran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to invoke the "ToEnglish" method in the main method so that my program will output the four-digit integer in English words. For example if I enter the integer 4321, I want my program to output Four Three Two One.
Any help would be much appreciated!


 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to define a static method oneDigit(int) in your class. And, because this method is a part of the ToEnglish class, as is main(), you can simplify the calls to "oneDigit(n1);", that is, you don't need the "ToEnglish." in front of it.
 
Joshua Corcoran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my updated version. I'm still unsure how to properly invoke the oneDigit method so that my output will print "Four Three Two One"

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could implement oneDigit() with a switch statement or a series of if statements...
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oneDigit() can also be implemented with one statement. Since you have a number, you can use that number to get a corresponding element in an array. Since you have a known finite set of corresponding strings, you can use a statically declared array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!