2017-03-08 169 views
-7

我該如何改變這種程序「從轉換所有溫度」到轉換「溫度,我想」從各種溫度要一個溫度

import java.util.Scanner; 


public class Suhu { 

    static double suhuawal; 
    static double suhuakhir; 

    static double CelToFah(double suhuawal) { 
     double cf; 
     cf = ((suhuawal*1.8)+32); 
     return cf; 
    } 

    static double CelToRem(double suhuawal) { 
     double cr; 
     cr = (suhuawal*0.8); 
     return cr; 
    } 

    static double CelToKel(double suhuawal) { 
     double ck; 
     ck = suhuawal+273.15; 
     return ck; 
    } 

    public static void main(String[] args) { 
     double x; 
     Scanner in = new Scanner(System.in); 
     System.out.print("Masukkan suhu awal: "); 
     x = in.nextDouble(); 
     suhuakhir = CelToFah(x); 
     System.out.println("Suhu Akhir Fahrenheit: "+suhuakhir); 
     suhuakhir = CelToRem(x); 
     System.out.println("Suhu Akhir Reamur: "+suhuakhir); 
     suhuakhir = CelToKel(x); 
     System.out.println("Suhu Akhir Kelvin: "+suhuakhir); 
    } 

} 

請不要改變車身結構,只需添加方法還是其他什麼東西,可以幫助我

+1

Downvoted:未提供合理的嘗試表明你不只是尋找一個免費搭乘 –

+0

好感謝您的評論 –

+0

_請不要改變身體結構,只是添加方法或其他可以幫助我的東西 - - 這不是'爲我做我的工作'網站。詢問你不明白的事情的具體問題,而不是告訴我們完成你的任務。 – csmckelvey

回答

-2
import java.util.Scanner; 


public class Suhu { 

static double suhuawal; 

    static double suhuakhir; 

    static double CelToFah(double suhuawal) 

    { 

    double cf; 

    cf = ((suhuawal*1.8)+32); 

    return cf; 

    } 

    static double CelToRem(double suhuawal) 

    { 

    double cr; 

    cr = (suhuawal*0.8); 

    return cr; 

    } 

    static double CelToKel(double suhuawal) 

    { 

    double ck; 

    ck = suhuawal+273.15; 

    return ck; 

    } 
    public static void main(String[] args) { 

    double x; 

       Scanner in = new Scanner(System.in); 
       System.out.print("Please give the value : "); 
       x = in.nextDouble(); 
       int chosen=0; 
       double ans=0; 
       System.out.print("Choose which one to convert to : "); 
     System.out.println("[1] Kelvin: "+suhuakhir); 
     System.out.println("[2] Fahrenheit: "+suhuakhir); 
     System.out.println("[3] Reamur: "+suhuakhir); 
     chosen=in.nextInt(); 
     switch (chosen) { 
    case 1: 
    ans = CelToKel(x); 
break; 
    case 2: 
    ans = CelToFah(x); 
    break; 
     case 3: 
    ans = CelToRem(x); 
    break; 

    default: 
    chosen=-1; 
    break; 
} 
if(-1==chosen)System.out.print("Wrong choice! "); 
else 
System.out.print("After conversion : "+ans); 


    } 

}