猜数字游戏
重点
1, JOptionPane.showInputDialog("Guess a number between 0 and 100")
2, JOptionPane.showMessageDialog(null, "Too high");
package chapter1;import javax.swing.JOptionPane;public class S1WrapUp {public static void main(String[] args) {int guess = -1;int count = 0;int num = (int)(Math.random() * 100);while(num != guess){guess = Integer.parseInt(JOptionPane.showInputDialog("Guess a number between 0 and 100"));if(guess > num){JOptionPane.showMessageDialog(null, "Too high");}if(guess < num){JOptionPane.showMessageDialog(null, "Too Low");}count ++;}JOptionPane.showMessageDialog(null, "Right");}}