大家帮帮我 我跪求大家了

gaomingrui 2006-06-27 07:05:03
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


错误在那里呀 我这没有报错信息啊
...全文
138 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenglin_piao 2006-06-27
  • 打赏
  • 举报
回复
while语句有问题,好象是死循环。

上面的do还有while下面的if,应该改一下这个循环。

这个地方while(option != 3),这样上下就做没必要的循环了,
我觉得应该把这个循环弄到一块儿,这样扩展性更好。
zebra007 2006-06-27
  • 打赏
  • 举报
回复
晚了一步

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

kevinliuu 2006-06-27
  • 打赏
  • 举报
回复
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
kevinliuu 2006-06-27
  • 打赏
  • 举报
回复
太多错误了,下次细心点

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧