3. ทำซ้ำ ๆ

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.

 
รหัสที่ 3-2  โปรแกรมคำนวณดัชนีมวลกาย (วนทำไม่รู้จบ) รุ่นปรับปรุง
import java.util.Scanner;
// โปรแกรมคำนวณดัชนีมวลกาย แบบวนทำไม่รู้จบ 
public class BodyMassIndex {
  public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);
    while (true) {
      System.out.print("น้ำหนัก (kg.) = ");
      double weight = kb.nextDouble();
      System.out.print("ความสูง (cm.) = ");
      double height = kb.nextDouble();
      double hm = height / 100.0;
      double bmi = weight / (hm * hm);
      System.out.println("ดัชนีมวลกาย = " + bmi);
    }
  }
}
©2009 S.Prasitjutrakul