icse-promo

Question

Use the switch case statement, write a menu driven program to do the following:

(a) To generate and print letters from A to Z & their Unicode

				
					Letter     unicode 
 A          65 
 B          66 
 C          67 
 -          -
 -          -
 -          -
 Z          90
				
			

(b) Display the following pattern iteration (looping) statement:

				
					1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
class program5
{
	public static void main(String[]args)
	{
	    int choice=0,i=0;
		Scanner sc=new Scanner(System.in);
		System.out.println("Press 1 for Unicode of A to Z ");
		System.out.println("Press 2 for pattern");
		System.out.print("Enter Your Choice:");
		choice = sc.nextInt();
		switch(choice)
		{
			case 1:
			        
					System.out.println("Letters : Unicode");
					for(i=65;i<=90;i++)
					{
						System.out.println((char)i+" : "+i);
					}
					break;
			case 2:
					int k=0,j=0;
					for(i=1;i<=5;i++)
					{
						k=1;
						for(j=1;j<=5;j++)
						{
							if(j<=i)
							{
								System.out.print(k);
								k++;
							}
							else
								System.out.print(" ");
						}
						System.out.println();
					}
					break;
			default:
					System.out.println("Invalid choice");
		}
	}
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *