Bootstrap

JAVA小练习5——模拟猜数字游戏,最多猜3次

import java.util.*;
public class Demo5 {

	public static void main(String[] args) 
	{
	Random random=new Random();
	int randomNumber=random.nextInt(10)+1;
	Scanner scanner=new Scanner(System.in);
	int count=0;
	while(count<3) {
		count++;
	System.out.println("请输入你猜的数字:");
	int guessNumber=scanner.nextInt();
	if(guessNumber>randomNumber) {
		System.out.println("猜大了");
	}else if(guessNumber<randomNumber) {
		System.out.println("猜小了");
	}else {
		System.out.println("猜对了");
		break;
	}
	
	}
	scanner.close();
}
			
}

;