JAVA Program to print following patterns with the help of users choice statement(switch-case).Print appropriate menu with options. (i) using for loop (ii) using while loop 1 2 3 4 5 A 1 2 3 4 A B 1 2 3 A B C 1 2 A B C D 1 A B C D E

  JAVA Program to print following patterns with the help of users choice statement(switch-case)


import java.util.*;                                                                                                                                       class Pattern                                                                                                                                          
{
public static void main()                                                                                                                           {
Scanner Sc=new Scanner(System.in);                                                                                           System.out.println(“Enter 1 for number pattern”);                                                                             System.out.println(“Enter 2 for alphabetical patter “);                                                 System.out.println(“Now give your choice “);                                                                                        int choice=Sc.nextInt();                                                                                                                          
 switch(choice)                                                                                                                                
{
case 1: for(int i=5;i>=1;i--)
{
for(int j=1;j<=I;j++)                                                
{
System.out.print(j+” “); }                                                                                                                      
System.out.println();
}      
break;                                                                                                                                                         case 2: char jh=’A’;                    
while(jh<=’E’)                                                                                
{
char kh=’A’;                                                                                                                                                       while(kh<=jh)                                                                                    
{
System.out.print(kh+” “);                                                                                                                           kh++;}                          
System.out.println();
jh++;
}  }  }  }  }


Output: Enter 1 for number pattern     
Enter 2 for alphabetical pattern                                                                                                                                             Now give your choice  1
  
12345
1234
123
12                                                
1
-------------------------------------------------------------------------------------

Just copy paste the code into the class file of Bluej compiler. Change the class name according to your's. 

Thanks for visting Programming in JAVA

Happy Coding !!



Post Comments

No comments:

Powered by Blogger.