这是一个猜数字的小程序~~ 在eclipse下运行没反应javaw.exe还很占cpu资源。。求救。。import javax.swing.JOptionPane;public class CH05EX15 {

public static void main(String[] args) 
    {

//declare the variables

int num,guess,diff;
String inputStr,outputStr;

boolean done;

num=(int)(Math.random()* 100);

    done= false;

    while(!done);
    {
     // Input your guess

inputStr = JOptionPane.showInputDialog
        ("Enter the number you guess.");
guess = Integer.parseInt(inputStr);
diff=num-guess;

if (diff==0)
{
outputStr= "You guessed the correct number.";

done= true;
}
else
if(diff>=50 && diff<=-50)
       outputStr= "The guess is very high or very low.";
       
    else
     if((50>diff||diff>=30) && (diff <=-30||-50<=diff))
           outputStr= "The guess is high or low.";
        else
         if((30>diff||diff>=15) &&(diff<=-15||-30<=diff))
         outputStr= "The guess is moderately.";
         else
         outputStr="The guess is somewhat high.";
    }
JOptionPane.showMessageDialog(null, outputStr,
"Result",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
             
    
    
}}

解决方案 »

  1.   

    给你改了一下,你看看吧。然后顺便bs下你发0分的帖子。
    import javax.swing.JOptionPane; public class CH05EX15 {  public static void main(String[] args){  int num,guess,diff; 
    String inputStr,outputStr;  boolean done;  num=(int)(Math.random()* 100);  done= false;  while(!done){ 
    inputStr = JOptionPane.showInputDialog("Enter the number you guess."); 
    guess = Integer.parseInt(inputStr); 
    diff = num - guess;  if (diff==0){ 
    outputStr= "You guessed the correct number."; 
    done= true; 

    else if(Math.abs(diff) >= 50) 
    outputStr= "The guess is very high or very low."; 
          
    else if((Math.abs(diff) < 50)||(Math.abs(diff) >= 30)) 
    outputStr= "The guess is high or low."; 
    else if((Math.abs(diff) < 30)||(Math.abs(diff) >= 15)) 
    outputStr= "The guess is moderately."; 
    else 
    outputStr="The guess is somewhat high."; 

    JOptionPane.showMessageDialog(null, outputStr, "Result", JOptionPane.INFORMATION_MESSAGE); //把这句移到while循环内
    }      
    System.exit(0);
        } 
      

  2.   

    为什么改了还是运行不起来呢?  javaw.exe 还死占cpu 只有这个程序占cpu、、哎。。
      

  3.   

    程序中有三个错误   改了就可以了1   while后面的分号不能要   要的话你的循环就结束了
    2   初始化outputStr="";   不初始化会出错
    3   你的输入界面未考虑用户点取消了你怎么做
      

  4.   

    我已经在www.nlld.net上给了你完整回答(见http://www.nlld.net/program/tiezijiyiqv.do?method=viewtiezi&id=1049)
    你对比一下你的判断条件,测试一下,你把&&、||我感觉用反了。为了便于测试,我把英文改成了汉语,有什么及时提问、交流!