import javax.swing.JOptionPane;
import java.util.*;
public class Figureguess_extension
{
public static void main(String args[])
{
int x;
int spread;
int userscore=100;
int systemscore=100;
String s;
Random rand=new Random();
for(int i=1;;i++)
{
s=JOptionPane.showInputDialog("Enter an positive integer less than 100");
x=Integer.parseInt(s);
spread=Math.abs(x-rand.nextInt(100));
switch(spread)
{
case 0:
userscore+=10;
systemscore-=10;
JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
continue;
case 1:
case 2:
case 3:
case 4:
case 5:
userscore+=5;
systemscore-=5;
JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
continue;
case 6:
case 7:
case 8:
case 9:
case 10:
userscore+=0;
systemscore-=0;
JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
continue;
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
userscore-=5;
systemscore+=5;
JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
continue;
default:
userscore-=10;
systemscore+=10;
JOptionPane.showMessageDialog(null, "user:"+userscore+" VS "+"system:"+systemscore,"results",JOptionPane.PLAIN_MESSAGE);
continue;
}
}
}
}
书上说break与continue不同,但是switch也是循环么?如果是循环,那么上面的程序continue就应该改为break!难怪不孚吾望!
以前一直以为只有for是循环!