猜数游戏:
package com.lovo.date;
import javax.swing.JOptionPane;
public class Random {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
int n = (int) (Math.random() * 41) + 60;
int m=1;
while (m!=n) {
i++;
String s = JOptionPane.showInputDialog(null, "请输入你猜的数");
m = Integer.parseInt(s);
if (m > n) {
JOptionPane.showMessageDialog(null, "大了");
} else if(m!=n) {
JOptionPane.showMessageDialog(null, "小了");
}
}
if(i<=4){
JOptionPane.showMessageDialog(null, "天才");
}else
JOptionPane.showMessageDialog(null, "你是笨蛋" + "猜了" + i
+ "次,终于猜对了!");
System.out.println(n);
}
}
break 结束当前循环;continue 结束本次循环进入下次循环;
package com.lovo.date;
import javax.swing.JOptionPane;
public class Random {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i = 0;
int n = (int) (Math.random() * 41) + 60;
int m=1;
while (m!=n) {
i++;
String s = JOptionPane.showInputDialog(null, "请输入你猜的数");
m = Integer.parseInt(s);
if (m > n) {
JOptionPane.showMessageDialog(null, "大了");
} else if(m!=n) {
JOptionPane.showMessageDialog(null, "小了");
}
}
if(i<=4){
JOptionPane.showMessageDialog(null, "天才");
}else
JOptionPane.showMessageDialog(null, "你是笨蛋" + "猜了" + i
+ "次,终于猜对了!");
System.out.println(n);
}
}
break 结束当前循环;continue 结束本次循环进入下次循环;