import javax.swing.JOptionPane;
public class Temperature 
{
   public static void main( String args[] )
   {
      int option;
      int degree1;
      int celsius1;
      int fahrenheit1;   
          
      String result;
      String degree;
      String fahrenheit;
      String input;       
      String celsius;    
     
      option = 0; 
  
      do
      (
            input = JOptionPane.showInputDialog(" 1 for Fahrenheit to Celsius\n" +" 2 for Celsius to Fahrenheit\n 3 to quit:" );
            
            
      )
      While ( option != 3 )
      
         
     {
         option = Double.parseDouble( input );
         
         if ( option == 1 )
        {
           degree = JOptionPane.showInputDialog( "Enter the degree in Fahrenheit: " );
         
           degree1 = Double.parseDouble( degree ); 
     
           celsius1 = ( degree1 - 32 ) * 5 / 9; 
     
           result = "The temp in Celsius is " + celsius1; 
     
           JOptionPane.showMessageDialog( null, result, "Result",  JOptionPane.INFORMATION_MESSAGE );
        } 
          
         if ( option == 2 )
        {  
            degree = JOptionPane.showInputDialog( "Enter degree in Celsius: " );
         
            degree1 = Double.parseDouble( degree ); 
     
            fahrenheit1= ( degree1 * 9 / 5 ) + 32;
     
            result = "The temp in Fahrenheit is " + fahrenheit1;
     
            JOptionPane.showMessageDialog( null, result, "Result",
               JOptionPane.INFORMATION_MESSAGE );
        }
         System.exit( 0 );
         
      } // end while loop
      
   } // end method Main
   
} // end class Temperature 
错误在那里呀  我这没有报错信息啊

解决方案 »

  1.   

    public class Temperature
    {
        public static void main(String args[])
        {
            int option;
            int degree1;
            int celsius1;
            int fahrenheit1;        String result;
            String degree;
            String fahrenheit;
            String input;
            String celsius;        option = 0;
            input = JOptionPane.showInputDialog(
                    " 1 for Fahrenheit to Celsius\n" +
                    " 2 for Celsius to Fahrenheit\n 3 to quit:");
            
            option = Integer.parseInt(input) ;
            
            while(option != 3)
            {
    //            option = Integer.parseInt(input);            if (option == 1)
                {
                    degree = JOptionPane.showInputDialog(
                            "Enter the degree in Fahrenheit: ");                degree1 = Integer.parseInt(degree);                celsius1 = (degree1 - 32) * 5 / 9;                result = "The temp in Celsius is " + celsius1;                JOptionPane.showMessageDialog(null, result, "Result",
                                                  JOptionPane.INFORMATION_MESSAGE);
                }            if (option == 2)
                {
                    degree = JOptionPane.showInputDialog(
                            "Enter degree in Celsius: ");                degree1 = Integer.parseInt(degree);                fahrenheit1 = (degree1 * 9 / 5) + 32;                result = "The temp in Fahrenheit is " + fahrenheit1;                JOptionPane.showMessageDialog(null, result, "Result",
                                                  JOptionPane.INFORMATION_MESSAGE);
                }
                System.exit(0);        } // end while loop    } // end method Main} // end class Temperature
      

  2.   

    晚了一步import javax.swing.JOptionPane;public class Temperature 
    {
       public static void main( String args[] )
       {
          int option;
          double degree1;
          double celsius1;
          double fahrenheit1;   
              
          String result;
          String degree;
          String fahrenheit;
          String input;       
          String celsius;    
         
          option = 0; 
      
          do
          {
            input = JOptionPane.showInputDialog( "1 for Fahrenheit to Celsiusn\n2 for Celsius to Fahrenheitn\n3 to quit" ); 
         
            option = Integer.parseInt( input );
             
            if ( option == 1 )
            {
               degree = JOptionPane.showInputDialog(" Enter the degree in Fahrenheit " );
             
               degree1 = Double.parseDouble( degree ); 
         
               celsius1 = ( degree1 - 32 )*5/9; 
         
               result = "The temp in Celsius is: "  + celsius1; 
         
               JOptionPane.showMessageDialog( null, result, "Result",  JOptionPane.INFORMATION_MESSAGE );
            } 
              
            if ( option == 2 )
            {  
                degree = JOptionPane.showInputDialog(" Enter degree in Celsius " );
             
                degree1 = Double.parseDouble( degree ); 
         
                fahrenheit1= ( degree1*9/5 ) + 32;
         
                result ="The temp in Fahrenheit is: "  + fahrenheit1;
         
                JOptionPane.showMessageDialog( null, result, "Result",  JOptionPane.INFORMATION_MESSAGE );
            }
            
             
          
           } while ( option != 3 );
          //end while loop
           System.exit( 0 );
       }//end method Main
       
    }//end class Temperature 
      

  3.   

    while语句有问题,好象是死循环。上面的do还有while下面的if,应该改一下这个循环。这个地方while(option != 3),这样上下就做没必要的循环了,
    我觉得应该把这个循环弄到一块儿,这样扩展性更好。