53 Math类的静态方法

 1 import java.util.Scanner;  //  错误写成 until
 2 
 3 class GuessNum{
 4     public static void main(String[] args) {
 5         Scanner sr  =  new Scanner(System.in);
 6         System.out.println("please input a number betwean 1 to 200");
 7         // int num = sr.nextInt();  // 错误 这样while循环就只针对一个值了
 8         int guessNum = (int)(Math.random()*100+1);   // random是Math的静态方法,忘记写()
 9 
10         while(true){
11             int num = sr.nextInt();
12             if(guessNum > num ){
13                 System.out.println("小了");
14             }else if(guessNum < num){
15                 System.out.println("大了");
16             }else{
17                 System.out.println("中了");
18                 break;
19             }
20         }
21     }
22 }

 

posted @ 2017-01-26 11:58  panw3i  阅读(340)  评论(0编辑  收藏  举报