Advertisements
Advertisements
Question
Write a menu driven program to display
- first five uppercase letters
- last five lowercase letters as per the user's choice.
Enter 1 to display uppercase letters and enter 2 to display lowercase letters.
Answer in Brief
Solution
import java.util.*;
public class Q10
{ public static void main(String args[])
{ Scanner in = new Scanner(System.in);
int x;
System.out.println("Enter 1 to display the first five upper case letters");
System.out.println("Enter 2 to display the last five lower case letters");
x = in.nextInt();
switch (x)
{case 1: for (int i = 65; i < 70; i++)
System.out.print((char) i + " ");
break;
case 2: for (int i = 117; i < 122; i++)
System.out.print((char) i + " ");
break;
default: System.out.println(" Invalid entry");
}}}
shaalaa.com
Is there an error in this question or solution?
Chapter 2: Library Classes - EXERCISES [Page 180]