1、使用if...else...完成成绩的四等分,优,良,一般,差;
public class Score{
public static void main(String args[]){
int score=1001;
if (score>=90&&score<=100){
System.out.println("Excellent");
}else if(score>=80&&score<90){
System.out.println("Good");
}else if(score>=60&&score<80){
System.out.println("General");
}else if(score>=0&&score<60){
System.out.println("Bad");
}else
{
System.out.println("Score is out of range ");
}
}
}
2、猜拳游戏
public class MorraDemo{
public static void main(String args[]){
char a='石';
char b='布';
if(a=='石'&&b=='剪'){
System.out.println("a is win!");
}else if(a=='石'&&b=='布'){
System.out.println("a is lose!");
}else if(a=='石'&&b=='石'){
System.out.println("a and b is equal!");
}
}
}
注意判定条件中if(a=='石'&&b=='石')里面是判定号,不是赋值号,因此需要填写==;