Sunday, October 8, 2017

Switch

Challenge: Write a program that reads a letter grade and displays “Excellent” if the letter is an A, “Good” if it is a B, “You can do better!” if it’s a C, “I’m afraid that’s not good” if it’s a D or F, and “Input Error!” in any other case. Implement a solution using o SWITCH statement.

import java.util.Scanner;


public class lab5_2

{
public static void main(String []args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter you grade:");
char answer=in.nextLine().charAt(0);
 
switch(answer)
{
    case 'A':case'a':
    System.out.println("Excellent");




    break;
    case 'B':case'b':
    System.out.println("Good");
    break;
    case 'C':case'c':
    System.out.println("You can do better!");
    break;
    case 'D':case'd':case 'F':case'f':
    System.out.println("I’m afraid that’s not good");
    break;
    default: System.out.println("Input Error!");
}
}
}

No comments:

Post a Comment