Results 1 to 6 of 6
- 02-26-2011, 12:24 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
What is wrong with this program!?
PLEASE HELP!
{
//-----------------------------------------------------------------
// Determines if the value input by the user is even or odd.
// Uses multiple dialog boxes for user interaction.
//-----------------------------------------------------------------
public static void main (String[] args)
{
String numStr, result;
int num, again;
do
{
numStr = JOptionPane.showInputDialog ("Enter an integer: ");
num = Integer.parseInt(numStr);
result = "That number is " + ((num%2 == 0) ? "even" : "odd");
JOptionPane.showMessageDialog (null, result);
again = JOptionPane.showConfirmDialog (null, "Do Another?");
}
while (again == JOptionPane.YES_OPTION);
}
}
:confused::confused::confused::confused::confused: :confused::confused::confused::confused::confused:
im using the current version of Dr java with Eclipse compiler 0.A48and Java
- 02-26-2011, 01:08 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
There are bits of the program missing. It would help if we could see the whole thing. (When posting code use the "code" tags: you put [code] at the start of the code and [/code] at the end. That way the formatting is preserved.)
Basically it is up to *you* to say what is wrong with the program. Does it compile? If not, and you can't understand the compiler messages, post them.
Does it compile but shows unexpected or unwanted behaviour (including runtime exceptions) when you run it? If so, describe that behaviour.
- 02-26-2011, 01:19 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Java Code:import javax.swing.JOptionPane; public class EvenOdd { //----------------------------------------------------------------- // Determines if the value input by the user is even or odd. // Uses multiple dialog boxes for user interaction. //----------------------------------------------------------------- public static void main (String[] args) { String numStr, result; int num, again; do { numStr = JOptionPane.showInputDialog ("Enter an integer: "); num = Integer.parseInt(numStr); result = "That number is " + ((num%2 == 0) ? "even" : "odd"); JOptionPane.showMessageDialog (null, result); again = JOptionPane.showConfirmDialog (null, "Do Another?"); } while (again == JOptionPane.YES_OPTION); } }
- 02-26-2011, 01:21 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
holy crap! as soon as i posted last, it started running >_< thanks for your help bro, appreciate it!(BTW u have a beautiful country)
- 02-26-2011, 01:29 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
it started running >_<
A simple typo with a bracket will confuse the compiler mightily! Anyway, I'm glad it's doing what you want.
Not so beautiful for the folks in Christchurch at the moment... (I passed through there in mid January and on both days I was there there were eathquakes: apparently they have been quite common since last October.)
- 02-26-2011, 02:11 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Whats wrong with my program?
By jwb4291 in forum New To JavaReplies: 7Last Post: 12-12-2010, 05:40 AM -
what the wrong in my program ><
By MSs.Java in forum New To JavaReplies: 4Last Post: 05-03-2010, 02:28 PM -
Wrong Order in Program Run
By HeatR216 in forum New To JavaReplies: 0Last Post: 03-25-2010, 09:41 PM -
What's wrong in my program...?
By Annatar in forum Java SoftwareReplies: 3Last Post: 10-31-2008, 07:03 AM -
what is wrong with this program ?
By Poor Bee in forum New To JavaReplies: 1Last Post: 05-07-2008, 08:23 PM
Bookmarks