import java.util.Scanner;
public class temptrans {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("簡易溫度互換程式:");
System.out.println("1:以攝氏轉華式 2:以華氏轉攝氏");
byte type = input.nextByte();
if(type == 2 ){
System.out.println("請輸入華氏溫度");
float F = input.nextFloat();
System.out.println("攝氏溫度為:"+((F-32)*5/9));
System.out.println("絕對溫度為:"+(((F-32)*5/9)+273.15));
}else if(type == 1 ){
System.out.println("請輸入攝氏溫度");
float C = input.nextFloat();
System.out.println("華氏溫度為:"+(9*C/5+32));
System.out.println("絕對溫度"+(C+273.15));
}else{
System.out.println("請輸入1或2,不要來亂!");
}
}
}
2009年1月14日 星期三
Java小練習(5)
本程式需要讓使用者輸入華氏或攝氏溫度,以進行互換。
#####source code starts ########################
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言