Hello people...i need help in my code. I have a confirm dialog below and it will ask you to repeat the program again. now my problem is that if i choose yes, it will exit the application. here's my code below.
import javax.swing.JOp tionPane;
public class palin {
public static void main (String args[]) {
String num, right, error, numint;
int number, num1, num2, num3, num4, num5;
numint = JOptionPane.sho wInputDialog( "Enter 5 digits:" );
number = Integer.parseIn t(numint);
num = number + "";
num1 = num.charAt(0);
num2 = num.charAt(1);
num3 = num.charAt(2);
num4 = num.charAt(3);
num5 = num.charAt(4);
right = "It is a PALINDROME!";
error = "It is NOT A PALINDROME!";
if (num1==num5 && num2==num4)
JOptionPane.sho wMessageDialog(
null, right, "Access Granted",
JOptionPane.INF ORMATION_MESSAG E);
else
JOptionPane.sho wMessageDialog(
null, error, "Access Denied",
JOptionPane.INF ORMATION_MESSAG E);
int choice = JOptionPane.sho wConfirmDialog (null, "Do you want to try it again?");
if (choice == JOptionPane.YES _OPTION)
System.exit(-1);
else if(choice == JOptionPane.NO_ OPTION)
System.exit(0);
}
}
hope you can help me guys. thank you!
import javax.swing.JOp tionPane;
public class palin {
public static void main (String args[]) {
String num, right, error, numint;
int number, num1, num2, num3, num4, num5;
numint = JOptionPane.sho wInputDialog( "Enter 5 digits:" );
number = Integer.parseIn t(numint);
num = number + "";
num1 = num.charAt(0);
num2 = num.charAt(1);
num3 = num.charAt(2);
num4 = num.charAt(3);
num5 = num.charAt(4);
right = "It is a PALINDROME!";
error = "It is NOT A PALINDROME!";
if (num1==num5 && num2==num4)
JOptionPane.sho wMessageDialog(
null, right, "Access Granted",
JOptionPane.INF ORMATION_MESSAG E);
else
JOptionPane.sho wMessageDialog(
null, error, "Access Denied",
JOptionPane.INF ORMATION_MESSAG E);
int choice = JOptionPane.sho wConfirmDialog (null, "Do you want to try it again?");
if (choice == JOptionPane.YES _OPTION)
System.exit(-1);
else if(choice == JOptionPane.NO_ OPTION)
System.exit(0);
}
}
hope you can help me guys. thank you!
Comment