打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
多重if


清哥好课堂

《最受欢迎的精准提升平台》

多重if
/***@Title: ${filename}*@Package: ${package_name}*@Description: ${todo}*多重if语法 if(条件1){  //语句1}else if (条件2){  //语句2}else if (条件3){  //语句3}else{  //语句n}注意:if...else配对,成对
else 有条件,这个条件是隐含,条件是与其配对的if条件的对立面**@author: 源代码资料尽在"清哥好课堂"公众号:qghktit*@date: ${date}${time}*@version: 1.0*/import java.util.Scanner;public class MultiIF { public static void main(String[] args) { /* 从键盘输入一个成绩 <60 不及格 60-70 合格 70-80 良好 80-90 优秀 90-100 超级优秀 */ //接收一个成绩 Scanner sc = new Scanner(System.in); System.out.println("please input your score:"); int score = sc.nextInt(); sc = null;// if (score>=0 && score<=100)// {// } //从左往右 if (score<60) // <60 { System.out.println("不合格"); } else if (score<70) // >=60 && <70 { System.out.println("及格"); } else if (score<80) //>=70 && <80 { System.out.println("良好"); } else if (score<90) //>=80 && <90 { System.out.println("优秀"); } else // >=90 { System.out.println("超级优秀"); }
//从右往左 if (score>=90) // >= 90 { System.out.println("超级优秀"); } else if (score>=80) //<90 && >=80 { System.out.println("优秀"); } else if (score>=70) //<80 && >=70 { System.out.println("良好"); } else if (score>=60) //<70 && >=60 { System.out.println("及格"); } else // <60 { System.out.println("不合格"); } } public static void main3(String[] args) { /* 从键盘接收一个数,判断这个数,是小于0,还是大于等于0且小于100,或者大于等于100 */ Scanner sc = new Scanner(System.in); System.out.println("please input a number:"); int num = sc.nextInt(); sc = null; //判断该数的区间// if (num <0) //小于0// {// System.out.println(num+"是小于0");// }// else if (/*num>=0 &&*/ num <100) //【0,100)// {// System.out.println(num+"是大于等于0且小于100");// }// else// {// System.out.println(num+"是大于等于100");// }
//从数轴的右边往左边 if (num >= 100) //大于等于100 { System.out.println(num+"是大于等于100"); } else if (num >= 0) // 小于100 且 大于等于0 { System.out.println(num+"是大于等于0且小于100"); } else // 小于0 { System.out.println(num+"是小于0"); } } public static void main2(String[] args) { /* 模拟出拳---从键盘接收一个数 0----表示出的是剪刀 1----表示出的是石头 2----表示出的是布 其它的,表示出错了 */ Scanner sc = new Scanner(System.in); System.out.println("请出拳(剪刀(0),石头(1),布(2)):"); int n ;//接收出拳的数字 n = sc.nextInt(); //判断出拳 if (n==0) //出拳是剪刀 { System.out.println("您出的是剪刀"); } else if (n==1) //出拳是石头 { System.out.println("您出的是石头"); } else if (n==2) //出拳是布 { System.out.println("您出的是布"); } else //出错的 { System.out.println("出错了,请正确出拳"); } } public static void main1(String[] args) { /* 中奖 中一等奖,奖品:得清哥面对面交流一天 中二等奖,奖品:得清哥视频交流一次 中三等奖,奖品:得清哥好课堂课程代金券一张 其它 :得:可以免费参与线下活动 */ System.out.println("兑奖,请输入一个数字:"); Scanner sc = new Scanner(System.in);
int t = sc.nextInt(); //表示中几等奖 sc = null; if (t == 1) //中一等奖 { System.out.println("得清哥面对面交流一天"); } else if (t == 2) //中二等奖 { System.out.println("得清哥视频交流一次"); } else if ( t== 3) //中三等奖 { System.out.println("得清哥好课堂课程代金券一张"); } else //其它 { System.out.println("可以免费参与线下活动"); } }}

清哥好课堂公众号

微信号 : qghktit

新浪微博:清哥好课堂

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Java语言基础知识整理汇总
Day2 第七个知识点 练习2
约瑟夫出圈问题
判断整数是否是对称数
java循环结构小游戏
统计字符数量
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服