if语句的用法

97 阅读1分钟
public class Test1 {
    public static void main(String[] args) {
        int i = (int)(6 * Math.random()) + 1;
        int j = (int)(6 * Math.random()) + 1;
        int k = (int)(6 * Math.random()) + 1;
        int count = i + j + k;
        System.out.println(count);

        // if 语句
        if (count > 15) {
            System.out.println("今天运气不错");
        }

        if (count > 10 && count <= 15) {
            System.out.println("今天手气还行");
        }

        if (count <= 10) {
            System.out.println("今天手气挺差的");
        }

        // if-else 语句
        double r = 4 * Math.random();
        double area = Math.PI * r * r;
        double circle = Math.PI * 2 * r;
        System.out.println(area);
        System.out.println(circle);

        if (area > circle) {
            System.out.println("面积比周长长");
        } else {
            System.out.println("面积比周长短");
        }

//        if-else-if 语句

          double age = (int)(100*Math.random());
          System.out.println("年龄是" + age +", 属于");

          if (age > 50) {
              System.out.println("老人");
          } else if (age < 50 && age > 10) {
              System.out.println("中年");
          } else {
              System.out.println("青年");
          }
    }
}