java-guess number
2017-05-01 本文已影响0人
amazing_bing
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;
}
}
}
}