1:运用三目运算符比较三个数的大小
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);//Scanner键盘录入,获取用户输入的信息System.out.println("输入三个数、猜猜谁最大!");
System.out.println("请输入a:");
int a = sc.nextInt();
System.out.println("请输入b");
int b = sc.nextInt();
System.out.println("请输入c");
int c = sc.nextInt();
int max = a > b ? (a > c ? a : c) : (b > c ? b : c);//三目运算符比较大小
System.out.println("最大值为:"+max);}
2:if-else语句判断成绩优劣
public static void main(String[] args) {
System.out.println("请输入你的成绩:");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if(i >= 90 && i <= 100 ){
System.out.println("哇塞! 你得了A等哦!继续加油!");
}else if(i >= 80 && i < 90){
System.out.println("哇哦! 你得了B等哦!继续加油!");
}else if(i >= 70 && i < 80){
System.out.println("不错呦!得了C等!多多努力!!!");
}else if(i >= 60 && i < 70){
System.out.println("嗨呀!D等呀!的多多努力啊!!!");
}else if(i >= 0 && i < 60 ){
System.out.println("怎么回事!E等唉,快加油吧!");
}else{
System.out.println("亲!你输入的信息有错!请重新输入!!");
}
}