Java基础(极客)——05、Java if判断语句的用法
来源:互联网 发布:兆芯cpu运行windows 编辑:程序博客网 时间:2024/06/05 03:11
* 1、Java If语句概述和使用格式
*
*
* */
public class IfDemo1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);//键盘输入,也就是在控制台输入
System.out.println("输入分数:");
int score = scanner.nextInt();
if (score >= 60) {
System.out.println(score + "及格");
}
}
}//class
/**
* 2、Java If语句使用格式2-if else语句
*
*
*/
public class IfDemo2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);//键盘输入,也就是在控制台输入
System.out.println("输入第一个数");
int a = scanner.nextInt();
System.out.println("输入第二个数");
int b = scanner.nextInt();
if (a > b) {
System.out.println(a + "是最大数");
} else {
System.out.println(b + "是最大数");
}
}
}//class
/**
* 3、Java If语句使用格式3-if嵌套语句
* 下面这些逻辑和swich case语句一样
*/
public class IfDemo3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);//键盘输入,也就是在控制台输入
System.out.println("输入5分之数字:");
int score = scanner.nextInt();
if (score == 5) {
System.out.println("优秀");
} else if (score == 4) {
System.out.println("良好");
} else if (score == 3) {
System.out.println("及格");
} else if (score >= 0 && score <= 2) {
System.out.println("不及格");
} else {
System.out.println("你输入的5分制有误");
}
}
}//class
/**
* 4、【Java If语句算法示例1】键盘输入Java Android sql三科分数 找最高分
*
*
*/
public class IfDemo4 {
public static void main(String[] args) {
//找到最高分
Scanner scanner = new Scanner(System.in);//键盘输入,也就是在控制台输入
System.out.println("输入java的分数");
int java = scanner.nextInt();
System.out.println("输入android的分数");
int android = scanner.nextInt();
System.out.println("输入sql的分数");
int sql = scanner.nextInt();
if (java >= android && java >= sql) {
System.out.println("最高分:" + java);
} else if (android > sql) {
System.out.println("最高分:" + android);
} else {
System.out.println("最高分:" + sql);
}
}
}//class
/**
* 5、【Java If语句算法示例2】选择法找三科分数最高分(未完持续)
*
*if(){}
*else if(){}
*和if(){}
*if(){}
*的区别
*如果 if(){}成立则else if(){}不执行了
*如果if(){}是否成立都会执行if(){}
*
*/
public class IfDemo5 {
public static void main(String[] args) {
//定义一个变量maxScore找到最高分:
Scanner scanner = new Scanner(System.in);//键盘输入,也就是在控制台输入
System.out.println("输入java分数:");
int java = scanner.nextInt();
System.out.println("输入android分数:");
int android = scanner.nextInt();
System.out.println("输入sql分数:");
int sql = scanner.nextInt();
//定义一个maxScore找到最高分
int maxScore = java;
if (maxScore <= android) {
maxScore = android;
}
if (maxScore <= sql) {
maxScore = sql;
}
System.out.println("最高分:" + maxScore);
}
}//class
http://download.csdn.net/detail/zhaihaohao1/8741715
视频下载:
http://c38.yunpan.360.cn/my/index/#%2F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%2Fjava%2F
- Java基础(极客)——05、Java if判断语句的用法
- if判断语句的格式:--Java基础018
- java基础if语句的学习
- 【尚学堂之行——第四天】Java编程之if...else if...else判断语句的简单运用
- 【基础】java 条件语句 if
- Java基础--->08.判断语句(if、else if、switch、while、do while)。
- java的if语句用法总结及总结
- Java基础语法——运算符、流程控制语句、if条件语句
- 老紫竹JAVA基础培训(5),IF语句的使用
- 老紫竹JAVA基础培训(5),IF语句的使用
- java的if else if语句的判断条件不能相同
- 基础知识—条件判断语句-if条件类型的语句
- TP5 if判断语句用法
- Java语言——else if语句嵌套的优化
- (基础二)java if语句学习
- Java基础之if语句案例
- Java基础-判断法则-if与switch
- Java编程——if语句
- nginx配置文件说明
- XenAPI (C#) Tips
- Oracle基础知识
- chrome https 信任自签名证书
- [LeetCode] Subsets
- Java基础(极客)——05、Java if判断语句的用法
- 编程之美---发帖“水王”扩展问题
- ABAP基础内容
- 海量数据处理---分而治之
- Redis的主从复制与集群配置实践
- 犹太人能够非常富裕的成功秘密
- 最简单的视频编码器:编译(libx264,libx265,libvpx)
- 黑马程序员—OC基础-- ==和 isEqual方法
- PHP与HTML的一些易混关系