版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qintian888/article/details/53968164
- public class IfTest {
- public static void main(String[] args) {
- int a = 200;
- /*
- if (布尔表达式) {
- 语句块 // 要想执行必须布尔表达式为真
- }*/
- if (a == 20) {
- System.out.println("a==20"); // 有条件地执行
- }
- System.out.println("after if...");
- }
- }
- class IfTest2 {
- public static void main(String[] args) {
- int a = 20;
- if (a == 200) {
- System.out.println("a==20");
- } else { // 否则, 如果if中的条件为假, 执行下面的语句
- System.out.println("else");
- }
- System.out.println("after if else ...");
- }
- }
- class IfTest3 {
- // 分支 : 多个条件, 只允许有一个执行
- public static void main(String[] args) {
- int a = 20;
- if (a == 10) {
- System.out.println("a==10");
- } else if (a == 20) {
- System.out.println("a==20");
- } else if (a == 30) {
- System.out.println("a==30");
- } else {
- System.out.println("else");
- }
- System.out.println("after if else if ...");
- }
- }
- class Exer3 {
- public static void main(String[] args) {
- /*
- 从命令行参数接收小明的期末成绩。
- 当成绩为100分时,奖励一辆BMW;
- 当成绩为(80,99]时,奖励一个台iphone6s;
- if (80 < score <= 99)
- 当成绩为[60,80]时,奖励一本参考书;
- 其它时,什么奖励也没有。
- 提示: 从命令行参数获取整数的代码:
- int score = Integer.parseInt(args[0]);
- */
- int score = Integer.parseInt(args[0]);
- if (score > 100 || score < 0) {
- System.out.println("输入的数据非法");
- } else if (score == 100) {
- System.out.println("奖励一辆BMW");
- } else if (score > 80 && score <= 99) {
- System.out.println("奖励一个台iphone6s");
- } else if (score >= 60 && score <= 80) {
- System.out.println("奖励一本参考书");
- } else {
- System.out.println("什么奖励也没有");
- }
- }
- }
- /*
- 大家都知道,男大当婚,女大当嫁。那么女方家长要嫁女儿,当然要提出一定的条件:高:180cm以上;富:财富1千万以上;帅:是。
- 如果这三个条件同时满足,则:“我一定要嫁给他!!!”
- 如果三个条件有为真的情况,则:“嫁吧,比上不足,比下有余。”
- 如果三个条件都不满足,则:“不嫁!”
- */
- public class IfTest {
- public static void main(String[] args) {
- int heigh = Integer.parseInt(args[0]);
- int money = Integer.parseInt(args[1]);
- boolean b = Boolean.parseBoolean(args[2]);
- if (heigh > 180 && money > 1000 && b == true) {
- System.out.println("我一定要嫁给他!!!");
- } else if (heigh > 180 || money > 1000 || b == true) {
- System.out.println("嫁吧,比上不足,比下有余");
- } else {
- System.out.println("不嫁!");
- }
- }
- }
- //编写程序:接收三个命令行字符串并转换为整数分别存入变量num1、num2、num3,对它们
- //进行排序(使用 if-else if-else),并且从小到大输出。
- public class IfTest1 {
- public static void main(String[] args) {
- int num1 = Integer.parseInt(args[0]);
- int num2 = Integer.parseInt(args[1]);
- int num3 = Integer.parseInt(args[2]);
- if (num1 > num2){
- if (num3 > num1){
- System.out.println(num2 + "," + num1 + "," + num3);
- } else if (num2 > num3) {
- System.out.println(num3 + "," + num2 + "," + num1);
- } else{
- System.out.println(num2 + "," + num3 + "," + num1);
- }
- }else {
- if (num3 > num2) {
- System.out.println(num1 + "," + num2 + "," + num3);
- }else if(num1 > num3) {
- System.out.println(num3 + "," + num1 + "," + num2);
- }else {
- System.out.println(num1 + "," + num3 + "," + num2);
- }
- }
- }
- }
- class IfTest11 {
- public static void main(String[] args) {
- int num1 = Integer.parseInt(args[0]);
- int num2 = Integer.parseInt(args[1]);
- int num3 = Integer.parseInt(args[2]);
- //比较交换3次
- //1和2
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
- //2和3
- if (num2 > num3) {
- int tmp = num2;
- num2 = num3;
- num3 = tmp;
- }
- //1和2
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
- System.out.println(num1 + "," + num2 + "," + num3);
- }
- }
- public class IfTest {
- public static void main(String[] args) {
- int a = 200;
- /*
- if (布尔表达式) {
- 语句块 // 要想执行必须布尔表达式为真
- }*/
- if (a == 20) {
- System.out.println("a==20"); // 有条件地执行
- }
- System.out.println("after if...");
- }
- }
- class IfTest2 {
- public static void main(String[] args) {
- int a = 20;
- if (a == 200) {
- System.out.println("a==20");
- } else { // 否则, 如果if中的条件为假, 执行下面的语句
- System.out.println("else");
- }
- System.out.println("after if else ...");
- }
- }
- class IfTest3 {
- // 分支 : 多个条件, 只允许有一个执行
- public static void main(String[] args) {
- int a = 20;
- if (a == 10) {
- System.out.println("a==10");
- } else if (a == 20) {
- System.out.println("a==20");
- } else if (a == 30) {
- System.out.println("a==30");
- } else {
- System.out.println("else");
- }
- System.out.println("after if else if ...");
- }
- }
- class Exer3 {
- public static void main(String[] args) {
- /*
- 从命令行参数接收小明的期末成绩。
- 当成绩为100分时,奖励一辆BMW;
- 当成绩为(80,99]时,奖励一个台iphone6s;
- if (80 < score <= 99)
- 当成绩为[60,80]时,奖励一本参考书;
- 其它时,什么奖励也没有。
- 提示: 从命令行参数获取整数的代码:
- int score = Integer.parseInt(args[0]);
- */
- int score = Integer.parseInt(args[0]);
- if (score > 100 || score < 0) {
- System.out.println("输入的数据非法");
- } else if (score == 100) {
- System.out.println("奖励一辆BMW");
- } else if (score > 80 && score <= 99) {
- System.out.println("奖励一个台iphone6s");
- } else if (score >= 60 && score <= 80) {
- System.out.println("奖励一本参考书");
- } else {
- System.out.println("什么奖励也没有");
- }
- }
- }
- /*
- 大家都知道,男大当婚,女大当嫁。那么女方家长要嫁女儿,当然要提出一定的条件:高:180cm以上;富:财富1千万以上;帅:是。
- 如果这三个条件同时满足,则:“我一定要嫁给他!!!”
- 如果三个条件有为真的情况,则:“嫁吧,比上不足,比下有余。”
- 如果三个条件都不满足,则:“不嫁!”
- */
- public class IfTest {
- public static void main(String[] args) {
- int heigh = Integer.parseInt(args[0]);
- int money = Integer.parseInt(args[1]);
- boolean b = Boolean.parseBoolean(args[2]);
- if (heigh > 180 && money > 1000 && b == true) {
- System.out.println("我一定要嫁给他!!!");
- } else if (heigh > 180 || money > 1000 || b == true) {
- System.out.println("嫁吧,比上不足,比下有余");
- } else {
- System.out.println("不嫁!");
- }
- }
- }
- //编写程序:接收三个命令行字符串并转换为整数分别存入变量num1、num2、num3,对它们
- //进行排序(使用 if-else if-else),并且从小到大输出。
- public class IfTest1 {
- public static void main(String[] args) {
- int num1 = Integer.parseInt(args[0]);
- int num2 = Integer.parseInt(args[1]);
- int num3 = Integer.parseInt(args[2]);
- if (num1 > num2){
- if (num3 > num1){
- System.out.println(num2 + "," + num1 + "," + num3);
- } else if (num2 > num3) {
- System.out.println(num3 + "," + num2 + "," + num1);
- } else{
- System.out.println(num2 + "," + num3 + "," + num1);
- }
- }else {
- if (num3 > num2) {
- System.out.println(num1 + "," + num2 + "," + num3);
- }else if(num1 > num3) {
- System.out.println(num3 + "," + num1 + "," + num2);
- }else {
- System.out.println(num1 + "," + num3 + "," + num2);
- }
- }
- }
- }
- class IfTest11 {
- public static void main(String[] args) {
- int num1 = Integer.parseInt(args[0]);
- int num2 = Integer.parseInt(args[1]);
- int num3 = Integer.parseInt(args[2]);
- //比较交换3次
- //1和2
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
- //2和3
- if (num2 > num3) {
- int tmp = num2;
- num2 = num3;
- num3 = tmp;
- }
- //1和2
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
- System.out.println(num1 + "," + num2 + "," + num3);
- }
- }