简单的Java判断语句及库函数的应用
import javax.swing.JOptionPane;
public class Guess {
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("输入你的猜测");
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("猜中了");
}
}