write a java program called PrintNumberInWord which prints ''ONE'',''TWO'',....,''NINE'',''OTHER'' if theint variable ''number'' 1,2,......,9,or other,respectively.Use (a) a ''nested if'' statement (b) a ''switch case'' statement
When you get a specification like this, you know you'll need to create the variable it mentions. So you'll need to make an `int number`. You'll want to know how to use a "nested if," or I'm thinking a series of else-ifs, but I don't know if that counts. It would certainly be more clear... You'll also want to be familiar with Java's switch statements. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html switch (variableName) { \(\qquad\)case value1: //do something \(\qquad\qquad\)break; //or else you'll do all the do somethings below. \(\qquad\)case value2: //do something else \(\qquad\qquad\)break; //or else you'll do all the do somethings below. \(\qquad\)default: //put here what to do for anything not covered in your cases. \(\qquad\qquad\)break;//because they have it in the link! } Familiarize yourself with that, and feel free to ask any more questions! I didn't go into detail because I'm tired, sorry. Good luck, and know that making a plan is the next step after finding out what you need to get done! :)
Let me know if you have any questions on this, @karan93 ! Or you could post your questions separately after closing this one, if you choose to do it like that.
Join our real-time social learning platform and learn together with your friends!