Ask Question
21 January, 21:41

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

+4
Answers (1)
  1. 21 January, 22:46
    0
    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);

    }

    }

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a switch statement that checks origLetter. If origLetter is 'a' or 'A', assign greekLetter with 'Alpha'. If origLetter is 'b' or 'B', ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers