Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

I need help. Please someone help me. Write a java program called PrintNumberInWord which printss "ONE","TWO",....,"NINE","OTHER" if the int variable "number" is 1,2,....,9, or other respectively. Use (a)a "nested if" statement (b)a "switch case" statement.

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
Following are my codings for the above question. (a) public class PrintNumberInWord { public static void main(String[]args) { int number=8; if(number==1) { System.out.print("ONE"); } else if(number==2) { System.out.print("TWO"); } else if(number==3) { System.out.print("THREE"); } else if(number==4) { System.out.print("FOUR"); } else if(number==5) { System.out.print("FIVE"); } else if(number==6) { System.out.print("SIX"); } else if(number==7) { System.out.print("SEVEN"); } else if(number==8) { System.out.print("EIGHT"); } else if(number==9) { System.out.print("NINE"); } else { System.out.print("OTHER"); } } }
(b)public class PrintNumberInWord1 { public static void main(String[]args) { int number=5; switch(number) { case 1: System.out.print("ONE"); break; case 2: System.out.print("TWO"); break; case 3: System.out.print("THREE"); break; case 4: System.out.print("FOUR"); break; case 5: System.out.print("FIVE"); break; case 6: System.out.print("SIX"); break; case 7: System.out.print("SEVEN"); break; case 8: System.out.print("EIGHT"); break; case 9: System.out.print("NINE"); break; default: System.out.print("OTHER"); } } }
Right so... before Java 5: public class JavaStringArrayTests1 { private String[] toppings = {"Cheese", "Pepperoni", "Black Olives"}; public static void main(String[] args) { int size = toppings.length; for (int i=0; i

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Oops... sorry... didn't even read what you need. But what is required to use seems a bit clunky and not good practice I would imagine. I would be easier to use the following if you are given a number: int number=5; private String[] numbers= {"ONE","TWO",....,"NINE"}; if(number>9) { System.out.println("OTHER"); } else { System.out.println(numbers[number-1]); }
Thanks a lot for the help @chris2332. But they want us to use only "nested if" not arrays. Is my answer right for the question? I am not sure.
Err... yes... the code is straight forward for if statements or switch/case statements!
Isn't nested if this if(a>0) { if(b<0) { } } Hw do we use this for the above queastion? That's vat is confusing me:(
it wouldn't seem necessary, but you could force a nesting by first checking for the "other" case where the int is not 0-9, and then if it is 0-9, run through your print ONE, etc. cases.
That would be nested, but it seems weird to nest something like that... like you said, it makes more sense when you have two separate conditionals, not just different outcomes of the same conditional.
(disclaimer, I have about 6 total hours of Java time... I came here looking for Python posts and saw your thread :) )
:) Bigg thanks for your help:)
I don't know how helpful that was :) but thanks :)

Not the answer you are looking for?

Search for more explanations.

Ask your own question