473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Return to Main Code

26
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.JOptionPane;


public class palin {

public static void main (String args[]) {


String num, right, error, numint;
int number, num1, num2, num3, num4, num5;

numint = JOptionPane.showInputDialog( "Enter 5 digits:" );

number = Integer.parseInt(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.showMessageDialog(
null, right, "Access Granted",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(
null, error, "Access Denied",
JOptionPane.INFORMATION_MESSAGE);

int choice = JOptionPane.showConfirmDialog (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!
Jul 12 '07 #1
3 1458
r035198x
13,262 8TB
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.JOptionPane;


public class palin {

public static void main (String args[]) {


String num, right, error, numint;
int number, num1, num2, num3, num4, num5;

numint = JOptionPane.showInputDialog( "Enter 5 digits:" );

number = Integer.parseInt(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.showMessageDialog(
null, right, "Access Granted",
JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(
null, error, "Access Denied",
JOptionPane.INFORMATION_MESSAGE);

int choice = JOptionPane.showConfirmDialog (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!
Use code tags when posting code
What do you think these lines tell the program to do?

Expand|Select|Wrap|Line Numbers
  1.      if (choice == JOptionPane.YES_OPTION)
  2.         System.exit(-1);
Jul 12 '07 #2
Synapse
26
I got that line from this forum too but it didn't work.
Jul 12 '07 #3
r035198x
13,262 8TB
I got that line from this forum too but it didn't work.
Well the important thing is not getting some lines of code, it's about understanding the code, so you can write your own anytime. Follow the logic of your code and try to understand what the statements in your code mean.
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: wl | last post by:
Hi all, Pls help with the following: I have a stand-alone java program which will need to return a return-code to the running script. I thought I could just use: return -1; inside the...
25
by: cppaddict | last post by:
I'd like to know what goes on under the hood when methods return objects. Eg, I have a simple Point class with two members _x and _y. It's constructor, copy constructor, assignment operator and...
32
by: Mike Machuidel | last post by:
Hi, I'm a game developer programming mostly in C and ASM for about 7 years. Today at work a colleague (a C++ programmer) yelled at me I'm a bad C programmer because I use "return(0);" instead...
8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
32
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: ...
37
by: Army1987 | last post by:
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its...
27
by: junky_fellow | last post by:
Guys, Can I return 0, from main() ? Is this equivalent to exit(EXIT_SUCCESS) ? thanks for any help...
46
by: Bill Cunningham | last post by:
I have heard that return -1 is not portable. So what would be the answer to portability in this case? What about exit(0) and exit (-1) or exit (1)? Or would it be best to stick with C's macros,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.