java学习之路 之 基本语法-程序流程控制-(if-else)语句练习题
来源:互联网 发布:js文本框提示信息 编辑:程序博客网 时间:2024/05/16 16:00
- public class IfTest {
-
- public static void main(String[] args) {
- int a = 200;
-
-
-
-
- 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 {
- 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) {
-
-
-
-
-
-
-
-
-
-
- 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("什么奖励也没有");
- }
- }
- }
-
-
-
-
-
-
-
- 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("不嫁!");
- }
- }
- }
-
-
-
- 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]);
-
-
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
-
- if (num2 > num3) {
- int tmp = num2;
- num2 = num3;
- num3 = tmp;
- }
-
- if (num1 > num2) {
- int tmp = num1;
- num1 = num2;
- num2 = tmp;
- }
- System.out.println(num1 + "," + num2 + "," + num3);
- }
- }
0 0