Hello friends,
I am new to Java. I want to create a application that keep asking question untill user exit the question. should be very simple. i do not know how to make a loop that will do it. if anyone can help, i will be very thankful.
Thanks
indianj
Here is my code:
Code:import javax.swing.*; import java.util.Scanner; public class HW2part2 { public static void main (String [] args){ String sex; String father; String mother; int mfSex; int Hfather; int Hmother; JOptionPane.showMessageDialog(null,":: Health Care Center ::","..: Welcome to Hadik's Movie Place :..",JOptionPane.INFORMATION_MESSAGE); sex = JOptionPane.showInputDialog("Enter Sex of Child\n1. Male\n2. Female"); mfSex = Integer.parseInt(sex); father = JOptionPane.showInputDialog("Enter the Height of the father"); Hfather = Integer.parseInt(father); mother = JOptionPane.showInputDialog("Enter the Height of the mother"); Hmother = Integer.parseInt(mother); boolean nogender; do { if (mfSex == 1){ int Hmale_child = ((Hmother * 13/12)+ Hfather)/2; double Hmale_childFeet = Hmale_child * 0.0833; System.out.println("Childs height is " + Hmale_child + " inches and " + Hmale_childFeet + " feet"); JOptionPane.showMessageDialog(null,"Male Child's Height is: "+Hmale_child+" Inch and "+Hmale_childFeet+"Feet","..: Welcome to Hadik's Movie Place :..",JOptionPane.INFORMATION_MESSAGE); System.exit (0); } if (mfSex == 2){ int Hfemale_child = ((Hfather * 12/13)+ Hmother)/2; double Hfemale_childFeet = Hfemale_child * 0.0833; JOptionPane.showMessageDialog(null,"female Child's Height is: "+Hfemale_child+" Inch and "+Hfemale_childFeet+"Feet","..: Welcome to Hadik's Movie Place :..",JOptionPane.INFORMATION_MESSAGE); break; } else{ nogender=true; // System.out.println("insterted the wrong number"); } } while (nogender); } }




Reply With Quote