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
错误在那里呀 我这没有报错信息啊
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
错误在那里呀 我这没有报错信息啊
{
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
{
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
我觉得应该把这个循环弄到一块儿,这样扩展性更好。