Write a menu driven program to display i. First five upper case letters ii. Last five lower case letters as per the user’s choice. Enter ‘1’ to display the upper case letters, ‘2’ to display lower case letters.
Answers
str1="Great Power";
newStr = "";
for i in range(0, len(str1)):
#Checks for lower case character
if str1[i].islower():
#Convert it into upper case using upper () function
newStr += str1[i].upper();
#Checks for upper case character
elif str1[i].isupper():
#Convert it into lower case using lower () function
newStr += str1[i].lower();
else:
newStr += str1[i];
Answer:
import java.util.*;
public class pattern
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("1. First five upper case letters");
System.out.println("2. Last five lower case letters");
System.out.println("Enter your choice");
int ch = in.nextInt();
switch(ch)
{
case 1:
{
int a;
char b;
for(a=65;a<=69;a++)
{
b=(char)a;
System.out.print(b+" ");
}
}
break;
case 2:
{
int c;
char d;
for(c=118;c<=122;c++)
{
d=(char)c;
System.out.print(d+" ");
}
}
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
Explanation: