190k views
4 votes
Write a switch statement that checks origLetter. If origLetter is 'a' or 'A', assign greekLetter with 'Alpha'. If origLetter is 'b' or 'B', assign greekLetter with 'Beta'. For any other character, assign greekLetter with 'Unknown'.

function greekLetter = ConvertAlphabet(origLetter)

% Complete the switch statement to assign greekSymbol with 'Alpha',
% 'Beta', or 'Unknown' based on origLetter
switch ( origLetter )
case 'a'
greekLetter = 'Alpha';
otherwise
greekLetter = 'Unknown';
end
end

User Richs
by
3.7k points

1 Answer

1 vote

Answer:

import java.util.Scanner;

public class num6 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Enter an alphabet");

char origLetter = in.next().charAt(0);

String greekLeter ="";

switch (origLetter){

case 'A' :

greekLeter="Alpha";

break;

case 'a':

greekLeter="Alpha";

break;

case 'B':

greekLeter= "Beta";

break;

case 'b':

greekLeter = "Beta";

default:

greekLeter="Unknown";

}

System.out.println("You entered the letter "+origLetter+" The greek letter is" +

" "+greekLeter);

}

}

Step-by-step explanation:

  • A complete Java program is given above
  • Using a the Scanner class, the user is prompted for a character which is received and stored in the variable origLetter
  • The switch statement implements four cases, case of A, a, B and b to handle lower and upper case characters and assigns the appropriate String to the variable greekLeter as specified by the question
  • Finally the letter entered and the greekLeter is printed out.
User Caesarxuchao
by
3.7k points