-
-
Save wdfx100/4221657 to your computer and use it in GitHub Desktop.
猜数字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input=new java.util.Scanner(System.in); | |
random=new java.util.Random(); | |
//取随机数 | |
int num=random.nextInt(100); | |
System.out.println(num); | |
boolean flag=true; | |
int count=0; | |
while(flag){ | |
System.out.println("请输入你的数字:"); | |
int i=input.nextInt(); | |
if(i>num){ | |
System.out.println("你猜的数字太大了!"); | |
count++; | |
}else if(i<num){ | |
System.out.println("你猜的数字太小了!"); | |
count++; | |
}else if(i==num){ | |
System.out.println("恭喜你猜对了!"); | |
System.out.println("你一共猜了"+count+"次!"); | |
flag=false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment