- 练习一:将学生的分数按照标准分为优,良,中,差级别。
publicclassTest01{
publicstaticvoid main(String args[]){
int score =80;
if(score >85&& score <=100){
System.out.println("成绩为优");
}
elseif(score >75&& score <=85){
System.out.println("成绩为良");
}
elseif(score >60&& score <=75){
System.out.println("成绩为中");
}
elseif(score <=60&& score >=0){
System.out.println("成绩为差");
}
elseif(score >100|| score <0){
System.out.println("成绩不再正常范围之内");
}
}
}
- 练习二:猜拳游戏:定义两个char类型变量,分别代表两个玩家出拳,使用if...else...对结果进行判断。
publicclassTest02{
publicstaticvoid main(String args[]){
char play1 =‘s‘;
char play2 =‘j‘;
if(play1 ==‘s‘&& play2 ==‘s‘){
System.out.println("平");
}
elseif(play1 ==‘s‘&& play2 ==‘j‘){
System.out.println("play1 win");
}
elseif(play1 ==‘s‘&& play2 ==‘b‘){
System.out.println("play2 win");
}
elseif(play1 ==‘j‘&& play2 ==‘s‘){
System.out.println("play2 win");
}
elseif(play1 ==‘j‘&& play2 ==‘j‘){
System.out.println("平");
}
elseif(play1 ==‘j‘&& play2 ==‘b‘){
System.out.println("play1 win");
}
elseif(play1 ==‘b‘&& play2 ==‘s‘){
System.out.println("play1 win");
}
elseif(play1 ==‘b‘&& play2 ==‘j‘){
System.out.println("play2 win");
}
elseif(play1 ==‘b‘&& play2 ==‘b‘){
System.out.println("平");
}
}
}
时间: 2024-10-29 03:36:50