java,小程序练习while和do while,猜数字

package test;
import java.util.Scanner;
//猜数字游戏
public class GuessGame {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//生成1到1000的随机数
		int num = (int)(Math.random()*1000+1); //藏起来的数
		System.out.println(num); //作弊--自己看一下结果
		int guess;
		do{
			System.out.println("猜吧!");
			guess = scan.nextInt(); //1,3要素
			if(guess==0){
				break;
			}else if(guess>num){
				System.out.println("太大了");
			}else if(guessnum){
				System.out.println("太大了");
			}else{
				System.out.println("太小了");
			}
			System.out.println("猜吧!");
			guess = scan.nextInt(); //3.循环变量的改变	
		}
		if(guess==num){
			System.out.println("恭喜你,猜对了");
		}else{
			System.out.println("下次再来吧!");
		}
		*/
		
	}
}





你可能感兴趣的:(java)