美文网首页
java--guess number game

java--guess number game

作者: amazing_bing | 来源:发表于2017-03-21 23:47 被阅读0次
    import java.util.Scanner;
    
    class Test {
        public static void main(String[] args) {
            for (int i =1;i < 10; i++) {
                double d = Math.random();
                System.out.println(d); 
            }
            Hello.Game();   
        }
    }
    
    
    
    /*
    * A: 案例演示
        * 需求:猜数字小游戏(数据在1-100之间))
        
    */
    class Hello {
        //defense be called this class to create
        public Hello() {}
    
        public static void Game(){
            //first step : get a number in your guess
            Scanner sc = new Scanner(System.in);
            System.out.println("Please. Type A Random Number (1-100): ");
            //second step : made a random number 
            int guessNum = (int)(Math.random()*100) + 1;
            //third step : guess 
            while(true) {
                int result = sc.nextInt();
                if( result > guessNum ) {
                    System.out.println("it is too big");
                } else if( result < guessNum ) {
                    System.out.println("it is too small");
                } else {
                    System.out.println("it is hit ");
                    break;
                }
            }
    
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:java--guess number game

          本文链接:https://www.haomeiwen.com/subject/knennttx.html