import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
System.out.println("给你一个1至100之间的整数,试着猜一猜这个数");
int realNumber = (int)(Math.random() * 100) + 1;
int yourGuess = 0;
String str = JOptionPane.showInputDialog("请输入你的猜测:");
yourGuess = Integer.parseInt(str);
while(yourGuess != realNumber) {
if(yourGuess > realNumber) {
str = JOptionPane.showInputDialog("猜大了,在输入你的猜测:");
yourGuess = Integer.parseInt(str);
}
else if(yourGuess < realNumber) {
str = JOptionPane.showInputDialog("猜小了,在输入你的猜测:");
yourGuess = Integer.parseInt(str);
}
}
System.out.println("猜对了!恭喜您");
}
}
小游戏_猜数_JAVA
最新推荐文章于 2021-02-28 14:38:48 发布