naturalCloud naturalCloud

记录精彩的程序人生

目录
java:分之循环判断
/    

java:分之循环判断

switch

 1// switch 
 2  public static float clac(int num1, int num2, @NotNull String fuhao) {
 3
 4        float result;
 5        switch (fuhao) {
 6            case "+":
 7                result = num1 + num2;
 8                break;
 9            case "-":
10                result = num1 - num2;
11                break;
12            case "*":
13                result = num1 * num2;
14                break;
15            default:
16                result = num1 / num2;
17                break;
18        }
19
20        return result;
21    }

while

 1    public static void loop() {
 2
 3        int a =0 ;
 4        StringBuilder builder = new StringBuilder();
 5        while ( a < 10) {
 6             builder.append(a);
 7
 8            a ++;
 9        }
10
11        System.out.printf("%s" , builder.toString());
12    }

for

 1 public static void for1(){
 2        int[]  arr1 =  {3,45,6,8,90,55};
 3        for (int i = 0; i < arr1.length; i++) {
 4            System.out.printf("%d \n",arr1[i]);
 5        }
 6
 7        for (int value :
 8                arr1) {
 9            System.out.printf("%d \n",value);
10
11        }
12    }

do ... while

1  public static  void  do1()
2    {
3        int a =  4;
4        do {
5            System.out.printf("%d \n" ,a *4 );
6            a ++;
7        }while (a < 15);
8    }

###if .else .if

 1 public static  void  if1() {
 2
 3        int a = 1;
 4
 5        float result = (float) (Math.random()  * 10 + a);
 6
 7        if (result > 10 && result < 100 ) {
 8             System.out.println("a");
 9        }else if (result > 200 && result < 250) {
10            System.out.println("b");
11        }else {
12            System.out.println("c");
13        }
14
15    }
16

标题:java:分之循环判断
作者:naturalCloud
地址:https://yunqiblog.cn/articles/2020/02/19/1582095223786.html