(JAVA)编程实现:从键盘输入摄氏温度,求对应的华氏温度值。

来源:百度知道 编辑:UC知道 时间:2024/05/29 15:58:41
C=(H-32)*5/9

/**
* 编译后直接从键盘输入数字就可以得出结果了
*
*/
public class wendu {
public static void main(String [] args){
long C=Integer.parseInt(args[0]);
//C=(H-32)*5/9
long H = C*9/5+32;
System.out.println(C+"摄氏温度"+"所对应的华氏温度值为:"+ H);

}
}

import java.util.Scanner;

public class Test {
Scanner cin = new Scanner(System.in);

public void convert() {
while (true) {
System.out.println("请输入摄氏温度值");
int c = cin.nextInt();
int h = c * 9 / 5 + 32;
System.out.println("转换后的华氏温度为 :" + h);
}
}

public static void main(String args[]) {
new Test().convert();
}
}

我的这个程序可以无限循环来计算,如果不想要无限循环的话那么就把while语句注掉