Java 输入三个数比大小

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("亲!你输入的信息有错!请重新输入!!");
}
}

  • 5
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值