class Test {
public static void main(String[] args) {
int x = 80;
if (x > 100 || x < 0) {
System.out.println("成绩有误");
}else if (x >= 90 && x <= 100) {
System.out.println("A等");
}else if (x >= 80 && x <= 89) {
System.out.println("B等");
}else if (x >= 70 && x <= 79) {
System.out.println("C等");
}else if (x >= 60 && x <= 69) {
System.out.println("D等");
}else if (x >= 0 && x <= 60) {
System.out.println("E等");
}
switch(x)
{
default:
y++;
case 3:
y++;
break;
case 4:
y++;
}
System.out.println("y="+y);
//y = 5;
16:根据输入的值,判断是星期几。(分别用if语句和switch语句实现)
输入:1
输出:星期1
import java.util.Scanner;
class Test {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
/*
System.out.println("请输入数字");
int x = sc.nextInt();
if (x == 1) {
System.out.println("x = " + "星期一");
}else if (x == 2) {
System.out.println("x = " + "星期二");
}else if (x == 3) {
System.out.println("x = " + "星期三");
}
else if (x == 4) {
System.out.println("x = " + "星期四");
}
else if (x == 5) {
System.out.println("x = " + "星期五");
}
else if (x == 6) {
System.out.println("x = " + "星期六");
}
else if (x == 7) {
System.out.println("x = " + "星期日");
}else {
System.out.println("您输入的值有误");
}*/
System.out.println("请输入数字");
int x = sc.nextInt();
switch (x) {
case 7:
System.out.println("星期日");
break;
case 1:
System.out.println("星期一");
break;
case 2:
System.out.println("星期二");
break;
case 3:
System.out.println("星期三");
break;
case 4:
System.out.println("星期四");
break;
case 5:
System.out.println("星期五");
break;
case 6:
System.out.println("星期六");
break;
default:
System.out.println("您输入的值有误");
break;
}