2. คำนวณ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 2-15  โปรแกรมอุณหภูมิจากเซลเซียสให้เป็นฟาเรนไฮต์ (ที่ทำงานผิด)
import java.util.Scanner;  
// โปรแกรมแปลงอุณหภูมิจากเซลเซียสให้เป็นฟาเรนไฮต์ 
public class Celsius2Fahrenheit {
  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);
    System.out.print("c = ");
    double c = kb.nextDouble();
    double f = (9/5)*c + 32;
    System.out.println("อุณหภูมิ " + c + " เซสเซียส = " + f + " ฟาเรนไฮต์");
  }
}
©2009 S.Prasitjutrakul