public class Test {
public static void main(String args[]){
int Fahrenheit = 0;//華氏溫度
int Celsius = 0;//攝氏溫度
byte temp[] = new byte[256];//暫時儲存鍵盤的輸入資訊
System.out.print("請輸入華氏溫度:");
try {
System.in.read(temp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Fahrenheit = Integer.parseInt(new String(temp).trim());//trim()函式去除字串中的換行和空白,防止字串解析成數值時解析出錯
Celsius = (int) ((Fahrenheit-32)/1.8);
System.out.print("轉換為攝氏溫度為:"+Celsius);
public class Test {
public static void main(String args[]){
int Fahrenheit = 0;//華氏溫度
int Celsius = 0;//攝氏溫度
byte temp[] = new byte[256];//暫時儲存鍵盤的輸入資訊
System.out.print("請輸入華氏溫度:");
try {
System.in.read(temp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Fahrenheit = Integer.parseInt(new String(temp).trim());//trim()函式去除字串中的換行和空白,防止字串解析成數值時解析出錯
Celsius = (int) ((Fahrenheit-32)/1.8);
System.out.print("轉換為攝氏溫度為:"+Celsius);
}
}