java 猜数字游戏案例
作者:互联网
import java.util.Random;
import java.util.Scanner;
public class caishuzi{
public static void main(String[] args){
Random r = new Random();
int number = r.nextInt(100)+1;
while(true){
Scanner sc =new Scanner(System.in);
System.out.println("请输入你要猜的数字:");
int guessNumber = sc.nextInt();
if(guessNumber > number){
System.out.println("你猜的数"+guessNumber+"大了");
} else if (guessNumber < number){
System.out.println("你猜的数"+guessNumber+"小了");
}else{
System.out.println("恭喜你猜中了");
break;
}
}
}
}
标签:java,游戏,guessNumber,System,number,案例,println,out 来源: https://www.cnblogs.com/zzyyds/p/15005122.html