|
-
Nov 10th, 2009, 07:53 AM
#1
Thread Starter
New Member
[RESOLVED] Help with JOptionPane
I'm in the US Marines and stationed in Japan. I'm taking an online Java Programming class (part of my degree curriculum) and am only in week 2. I have the following task:
Write a Java program that reads an integer and checks whether it is even.
If your input is 25, your output should be:
Is 25 even?
false
If your input is 2000, your output should be:
Is 2000 even?
true
Also, the program must check if the number the user entered is between 1 and 1000.
If your input is 25, your output should be:
The number 25 between 1 and 1000 is true.
If your input is 2000, your output should be:
The number 2000 between 1 and 1000 is false.
1.The input and output must use JOptionPane dialog and display boxes.
My code thus far is:
Code:
import javax.swing.JOptionPane;
public class NumberChecker {
public static void main (String args[]) {
// Prompt the user to enter a number
String numberString = JOptionPane.showInputDialog(null, "Enter a number:", "Number Checker", JOptionPane.QUESTION_MESSAGE);
// Convert the string into an int value
int number = Integer.parseInt(numberString);
// Check if the number is even
int isEven; {
number = number % 2;
// Display the result in a message dialog box declaring if it is even or odd
JOptionPane.showMessageDialog(null, "Is " + number + " an even number?\n> " + isEven, "Number Checker", JOptionPane.INFORMATION_MESSAGE);}
}
// Check if the number is in the prescribed range
boolean isRange; {
return ! ((1 < number) && (number < 1000));
// Display the result in a message dialog box declaring if it falls in the prescribed range
JOptionPane.showMessageDialog(null, "Is the number " + number + " between 1 and 1000?\n> " + isRange, "Range Checker", JOptionPane.INFORMATION_MESSAGE);}
{
System.exit (0);
}
}
My problem is that when I go to compile, I'm receiving errors for the return ! and an error code for my range checker saying that it is looking for a symbol. Can anyone tell me what I'm doing wrong and why?
Thank you in advance!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|