使用java.lang.Math类,生成100个0到99之间的随机整数,找出它们之中的最大者和最小者...

package test01;   
public class RandomNum2 {   
  
    public static void main(String[] args) {   
        int min = 99;   
        int max = 0;   
        int temp;   
        int count = 0;   
        for (int i = 0; i < 100; i++) {   
            temp = (int) (Math.random() * 100);   
            // System.out.println(temp);   
            if (temp > 50) {   
                count++;   
            }   
  
            if (min > temp) {   
                min = temp;   
            }   
  
            if (max < temp) {   
                max = temp;   
            }   
        }   
        System.out.println("Max is:" + max);   
        System.out.println("Min is:" + min);   
        System.out.println("The count that bigger than 50 is:" + count);   
    }   
} 

 

你可能感兴趣的:(java基础,Java)