Page 48 - Sanko_Sixth Edition
P. 48

Else                                                  Scanner sc=new Scanner(System.in);
          {                                                     Int a;

          System.out.println(“The Greatest number is”+c);       System.out.println(“Enter a Number(betweeen 1 to
                                                                10) :”);
          }
                                                                a=sc.nextInt();
          }
                                                                Switch(a)
          }
                                                                {
          3. Switch .................case
                                                                case 1 :   System.out.println(“ONE”);

          Syntax of switch …..............case                  break;


                                                                case 2:   System.out.println(“TWO”);
          Switch(variable or Expression)
                                                                break;
          {
                                                                case 3 :   System.out.println(“THREE”);
          case 1 :   statement;
                                                                break;
          break;
                                                                case 4 :   System.out.println(“FOUR”);
          case 2 :   statement;
                                                                break;
          break;
                                                                case 5 :   System.out.println(“FIVE”);
          case 3 :   statement;
                                                                break;
          break;
                                                                case 6 :   System.out.println(“SIX”);
          …...........................
                                                                break;
          …............................
                                                                case 7 :   System.out.println(“SEVEN”);
          default:
                                                                break;
          Statement ;
                                                                case 8 :   System.out.println(“EIGHT”);
          }
                                                                break;

          Example :                                             case 9 :   System.out.println(“NINE”);
                                                                break;
          Write a program in java to input any number( 1 to
          10) and print it in word.                             case 10 :   System.out.println(“TEN”);


                                                                break;
          Solution :
                                                                default : System.out.println(“wrong entry”);
          Import java.util.Scanner;
                                                                }
          Class numberinword
                                                                }
          {
                                                                }
          Public static void main()

          {
                                                                                        (to be continued.............)


                                                                                                             42
   43   44   45   46   47   48   49   50   51   52   53