JAVA使用图形用户界面编写一个猜数游戏程序是什么?
展开全部
package GNumber;
import javax.swing.JOptionPane;
public class GNumber { final static int NUM = (int) (Math.random() * 10);
public static void main(String args[]) {
String strNum = JOptionPane.showInputDialog("请输入您猜的数:");
boolean flag = true;
while (flag) {
int number = Integer.parseInt(strNum);
if (number == NUM) {
JOptionPane.showMessageDialog(null, "恭喜您猜数正确!");
flag = false;
} else if (number < NUM) {
strNum = JOptionPane.showInputDialog("小于正确数,请重新输入:");
} else {
strNum = JOptionPane.showInputDialog("大于正确数,请重新输入:");
}
}
}
}
import javax.swing.JOptionPane;
public class GNumber { final static int NUM = (int) (Math.random() * 10);
public static void main(String args[]) {
String strNum = JOptionPane.showInputDialog("请输入您猜的数:");
boolean flag = true;
while (flag) {
int number = Integer.parseInt(strNum);
if (number == NUM) {
JOptionPane.showMessageDialog(null, "恭喜您猜数正确!");
flag = false;
} else if (number < NUM) {
strNum = JOptionPane.showInputDialog("小于正确数,请重新输入:");
} else {
strNum = JOptionPane.showInputDialog("大于正确数,请重新输入:");
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询