Computer Science, asked by rajeshwarivaangadi, 7 months ago

10) Rewrite the following if - construct using switch case statement.
if( x==1)
System.out.println("one");
else if ( x==10)
System.out.println("ten");
else if(x==100)
System.out.println("Hundred");
else
System.out.println("Invalid number");​

Answers

Answered by imtiyazallam
21

Answer:

switch(x){

   case 1:

       System.out.println("one");

       break;

   case 10:

       System.out.println("ten");

       break;

   case 100:

       System.out.println("Hundred");

       break;

    default:

       System.out.println("Invalid number");

}

Answered by anindyaadhikari13
6

Question:-

Rewrite the code using switch case statement.

Solution:-

The given code can be written using switch case statement as,

switch (x)

{

case 1:

System.out.println("One");

break;

case 10:

System.out.println("Ten");

break;

case 100:

System.out.println("Hundred");

break;

default: System.out.println("Invalid number ");

}

Similar questions