-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfSwitch.java
More file actions
62 lines (54 loc) · 1.13 KB
/
Copy pathIfSwitch.java
File metadata and controls
62 lines (54 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package basic.hello;
public class IfSwitch {
public static void PrintIf()
{
int x = 30;
if( x == 10 )
{
System.out.println("Value of X is 10");
}else if( x == 20 )
{
System.out.println("Value of X is 20");
}else if( x == 30 )
{
System.out.println("Value of X is 30");
}else
{
System.out.println("这是 else 语句");
}
}
public static void PrintSwitch()
{
char grade = 'B';
/*
* A输出优秀
* B和C输出良好
* D输出及格
* F输出不及格
* 不在范围内,输出未知等级
*/
switch(grade)
{
case 'A' :
System.out.println("优秀");
break;
case 'B' :
case 'C' :
System.out.println("良好");
break;
case 'D' :
System.out.println("及格");
break;
case 'F' :
System.out.println("不及格");
break;
default :
System.out.println("未知等级");
}
System.out.println("你的等级是 " + grade);
}
public static void main(String[] args) {
PrintIf();
PrintSwitch();
}
}