import javax.swing.JOptionPane;
public class OMG {
public static void main(String[] args) {
int num=1;
char option='Y';
while ((option=='Y')||(option=='y')){
if (num==1){
JOptionPane.showMessageDialog(null, "Count: "+num);
String ops=JOptionPane.showInputDialog("Do you want to count again? Y/N?");
option=ops.charAt(0);
num++;
}
else {
JOptionPane.showMessageDialog(null, "Count: "+num);
String ops=JOptionPane.showInputDialog("Do you want to count again? Y/N?");
option=ops.charAt(0);
num++;
}
}
JOptionPane.showMessageDialog(null, "Final Count "+num);
}
}
What you see above is a Java Program that will ask if the User wants to Count, if the user inputs either a Yes Answer ('Y' or a 'y'), the integer "x" will increment, but when I input a NO answer ('N' or a 'n') the program should output the Final Count or the Last number. But the problem is when I put a NO answer the program still increment Once and output a wrong answer. For Example the Last number is 5, but the Output will become 6.
Please Help