reallarc
New member
จารย์ให้เขียน JAVA หาค่า BMI อ่างับ
ผมก็เขียนแย้ว แต่คราวนี้ มีปัญหาที่ว่า หากคนที่เค้ากรอกข้อมูลมาผิดนี่ เราจะทำโปรแกรมให้เค้ากรอกใหม่ จนกว่าจะถูกแล้วค่อยผ่านไปทำข้อต่อไป นี่ทำยังไงเหรองับ
นี่ ที่ผมเขียนมางับ รบกวนด้วยน้า
import javax.swing.JOptionPane;
public class BMI {
public static void main(String[] args){
Object sexList[];//make array sexList
sexList = new String[2];
sexList[0] = "Man";
sexList[1] = "Woman";
//make choice for man or woman
Object test = JOptionPane.showInputDialog(null,"select your sex ?", "choose your sex",JOptionPane.QUESTION_MESSAGE, null, sexList, null);
String WeightString = JOptionPane.showInputDialog("Enter your Weight(Kg)");//input weight
double Weight=Double.parseDouble(WeightString);//cast weight string to double
String HeightString = JOptionPane.showInputDialog("Enter your Height(Cm)");//inputheight
double Height=Double.parseDouble(HeightString);//cast height string to double
double bmi=Weight/(Height*Height)*10000;// make variable BMI !!
System.out.println("BMI = "+bmi);
if (Weight>635||Weight250||Height=7 && bmi25 && bmi19.397959183673468 && bmi=7 && bmi22.908163265306122 && bmi19.397959183673468 && bmi
ผมก็เขียนแย้ว แต่คราวนี้ มีปัญหาที่ว่า หากคนที่เค้ากรอกข้อมูลมาผิดนี่ เราจะทำโปรแกรมให้เค้ากรอกใหม่ จนกว่าจะถูกแล้วค่อยผ่านไปทำข้อต่อไป นี่ทำยังไงเหรองับ
นี่ ที่ผมเขียนมางับ รบกวนด้วยน้า
import javax.swing.JOptionPane;
public class BMI {
public static void main(String[] args){
Object sexList[];//make array sexList
sexList = new String[2];
sexList[0] = "Man";
sexList[1] = "Woman";
//make choice for man or woman
Object test = JOptionPane.showInputDialog(null,"select your sex ?", "choose your sex",JOptionPane.QUESTION_MESSAGE, null, sexList, null);
String WeightString = JOptionPane.showInputDialog("Enter your Weight(Kg)");//input weight
double Weight=Double.parseDouble(WeightString);//cast weight string to double
String HeightString = JOptionPane.showInputDialog("Enter your Height(Cm)");//inputheight
double Height=Double.parseDouble(HeightString);//cast height string to double
double bmi=Weight/(Height*Height)*10000;// make variable BMI !!
System.out.println("BMI = "+bmi);
if (Weight>635||Weight250||Height=7 && bmi25 && bmi19.397959183673468 && bmi=7 && bmi22.908163265306122 && bmi19.397959183673468 && bmi