首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

猜数目字游戏

2012-12-21 
猜数字游戏重点1, JOptionPane.showInputDialog(Guess a number between 0 and 100)2, JOptionPane.show

猜数字游戏
重点
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");}}

热点排行