找高手做JAVA 里SWITCH 编程(题是英文的)

来源:百度知道 编辑:UC知道 时间:2024/06/20 16:11:28
Exercise on Switch Statement

For the following questions do:

1. Design a program that uses select case statement to determine the arithmetic operation on two numbers then display the output. For example any of the following letters can perform an arithmetic operation and display the output:

A is used to add two numbers
S is used to subtract two numbers
M is used to multiply two numbers
D is used to divide two numbers

2. Design a program that reads in a single digit number between 0-9 and
display it in English word, the program should display an error message if the number entered is less than 0 or greater than 9.

3. Design a program to determine grades in a course with three quizzes
(each quiz/test is out of 10).
Grades are determined by:

A is an average of 9 or better,
B is an average of 8,
C is an average of 7,
D is an average of 5 and 6
F is an average less

1.
while(true)switch(System.in.read()){
case '\r':break;
case '\n':break;
case -1:break;
case 'A':System.out.println("A is used to add two numbers");break;
case 'S':System.out.println("S is used to subtract two numbers");break;
case 'M':System.out.println("M is used to multiply two numbers");break;
case 'D':System.out.println("D is used to divide two numbers");break;
default :System.out.println("Invalid Input");break;
}

2.
Scanner scn=new Scanner(System.in);
while(scn.hasNextInt())switch(scn.nextInt()){
case 0:System.out.println("ZERO");break;
case 1:System.out.println("ONE");break;
case 2:System.out.println("TWO");break;
case 3:System.out.println("THREE");break;
case 4:System.out.println(