Computer Science, asked by divyanshi2112, 8 months ago

write a menu driven program in java to display:
(i)first five upper case letters
(ii)last five lower case letters
as per the user's choice
enter '1' to display upper case letters and enter '2' to display lower case letters​

Answers

Answered by Anonymous
8

Answer:

Alphabets in lowercase and uppercase can be printed using two methods, first is using ASCII values and second is to directly print values from ‘A’ to ‘Z’ using loops. Below are the implementation of both methods:

Using ASCII values:

ASCII value of uppercase alphabets – 65 to 90.

ASCII value of lowercase alphabets – 97 to 122.

C++

// C++ program to print alphabets

#include <iostream>

using namespace std;

// Function to print the alphabet

// in lower case

void lowercaseAlphabets()

{

// lowercase

for (int c = 97; c <= 122; ++c)

cout << c << " ";

cout << endl;

}

// Function to print the alphabet

// in upper case

void uppercaseAlphabets()

{

// uppercase

for (int c = 65; c <= 90; ++c)

cout << c << " ";

cout << endl;

}

// Driver code

int main()

{

cout << "Uppercase Alphabets" << endl;

uppercaseAlphabets(ch);

cout << "Lowercase Alphabets " << endl;

lowercaseAlphabets(ch);

return 0;

}

Answered by parthpawarcool24
0

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:

Similar questions