d051.
糟糕,我發燒了!
--
板橋高中教學題
| From: [118.166.0.118] |
發表日期
:
2013-08-13 17:37
剛學java不久,看網路上很多方法,
不知道該用round還是BigDecimal?
class temp
{
public static void main(String[] args)
{
change1 c1 = new change1();
change2 c2 = new change2();
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.print("查詢攝氏(1)或華氏(2):");
int x = sc.nextInt();
System.out.print("\n體溫為:");
float t = sc.nextFloat();
if(t>=-460 && t<=2147483647)
{
switch(x)
{
case 1:
System.out.println("\n攝氏溫度為:"+c1.change1(t));
break;
case 2:
System.out.println("\n華氏溫度為:"+c2.change2(t));
break;
default:
System.out.println("\n請輸入正確的查詢編號!");
break;
}
}
else
{
System.out.println("\n想騙誰?!正常人有這種溫度嗎?");
}
}
}
class change1
{
float c;//攝氏
float h;//華氏
float change1(float h)
{
this.h = h;
this.c = (this.h-32)*5/9;
return this.c;
}
}
class change2
{
float c;//攝氏
float h;//華氏
float change2(float c)
{
this.c = c;
this.h = (this.c*9/5) - 32;
return this.h;
}
}