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-7  โปรแกรมคำนวณพื้นที่ของวงกลมจากรัศมีที่รับทางแป้นพิมพ์
import java.util.Scanner;
// โปรแกรมคำนวณพื้นที่ของวงกลม 
public class CircleArea {
  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);
    System.out.print("รัศมี = ");
    double r = kb.nextDouble();
    double area = 3.14159 * r * r;
    System.out.println("วงกลมมีพื้นที่ = " + area);
  }
}
©2009 S.Prasitjutrakul