public class Sample { private static int selection = Integer.parseInt(JOptionPane.showInputDialog( null, "Please Selecti"));; public static boolean Condition() { if (selection >= 4) { JOptionPane.showMessageDialog(null, "There are only three choices!"); return true; } else if (selection <= 0) { JOptionPane.showMessageDialog(null, "You didn't Make A Choice!"); return true; } else { //if i remove this else block the program will ask //for a return statement return false; } } public void selection() { switch (selection) { case 1: JOptionPane.showMessageDialog(null, "Chocolate"); break; case 2: JOptionPane.showMessageDialog(null, "Vanilla"); break; case 3: JOptionPane.showMessageDialog(null, "Banana"); break; } } public static void main(String[] args) { do { Sample a = new Sample(); a.selection(); } while (Condition()); } }
try to run it in false condition...
in true condition everything is fine but whats going on in false condition.