java - Math Class

The java Math class

Help mathematics class Math class is a very useful, very simple to use, this special class, first of all he and the String class are the same as modified by the final, it can not have subclasses, there is its constructor is private, that is, we can not construct new methods in other classes Math object, then how can we call its methods, its original all the methods are static, that is, the class name can be used directly to access the method.

Exercise 1: randomly generates a random number between 1 and 10, the digital input of the random number is the same as winning.

Package com.test.day01; 

Import java.util.Random;
 Import java.util.Scanner; 

public  class Lottery {
     // randomly generates a random number between 1 and 10 (including 10), the same number as the random number input winning. 
    public  void loteery () { 
        Scanner SC = new new Scanner (the System.in);
         // generates a random number call Random 
        int I = ( int ) (Math.random () * (10) + 1'd );
         // the System.out. the println (I); 
        int n-= sc.nextInt ();
         IF (I == n-) { 
            System.out.println ( "Congratulations, you will be a"  );
        }else{
            System.out.println("谢谢参与");
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Lottery ll = new Lottery();
        ll.loteery();
    }

}

Exercise 2: Enter the number and if the number of randomly generated winning is the same, less than three times to achieve 3-5 display smart display is also good yo more than five times today show your poor luck Yo.

 

Guess you like

Origin www.cnblogs.com/yaojun3/p/11517763.html