Write a menu driven program to generate the upper case letters from Z to A and lower case letters from 'a' to 'z' as per the user's choice. Enter '1' to display upper case letters from Z to A and Enter '2' to display lower case letters from a to z.
import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter '1' to display upper case letters from Z to A");
System.out.println("Enter '2' to display lower case letters from a to z");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
int count = 0;
switch (ch)
{
case 1: for (int i = 90; i > 64; i--)
{
char c = (char)i; System.out.print(c);
}
break;
case 2: for (int i = 97; i < 123; i++)
{
char c = (char)i; System.out.print(c);
}
break;
default: System.out.println("Incorrect Choice");
}
}
}
No comments:
Post a Comment