| | |
Odd/Even Code
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 3
Reputation:
Solved Threads: 0
[QUOTE=Babyblues]Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this?
Here is what I have so far, but the program is not recognizing the (number) after if ( number). So if anyone can help I would sure appreciate it.
mport javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
/** Creates a new instance of EvenOdd */
public EvenOdd() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String firstNumber; // first string entered by user
int number; // number to be read
int even; // number if even
int odd; // number if odd
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
if ( number%2 == 0 );
System.out.print( " Number is EVEN " );
I am having trouble with my Odd/ Even Code. Can anyone help me with this?
Here is what I have so far, but the program is not recognizing the (number) after if ( number). So if anyone can help I would sure appreciate it.
mport javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
/** Creates a new instance of EvenOdd */
public EvenOdd() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String firstNumber; // first string entered by user
int number; // number to be read
int even; // number if even
int odd; // number if odd
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
if ( number%2 == 0 );
System.out.print( " Number is EVEN " );
•
•
Join Date: Sep 2004
Posts: 8
Reputation:
Solved Threads: 0
[QUOTE=Babyblues]
Well, you are trying to use "number" in your if statement. You do not have number set to any value. Maybe you meant "firstNumber" instead of "number".That should get you going in the right direction
•
•
•
•
Originally Posted by Babyblues
Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this?
Here is what I have so far, but the program is not recognizing the (number) after if ( number). So if anyone can help I would sure appreciate it.
mport javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
/** Creates a new instance of EvenOdd */
public EvenOdd() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String firstNumber; // first string entered by user
int number; // number to be read
int even; // number if even
int odd; // number if odd
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
if ( number%2 == 0 );
System.out.print( " Number is EVEN " );
Well, you are trying to use "number" in your if statement. You do not have number set to any value. Maybe you meant "firstNumber" instead of "number".That should get you going in the right direction
try it now
import javax.swing.JOptionPane; // program uses JOptionPane
public class EvenOdd {
public static void main(String[] args) {
String firstNumber;
int number;
firstNumber = JOptionPane.showInputDialog( null, " Enter a number" );
number = Integer.parseInt(firstNumber);
if ( number%2 == 0 ){
System.out.print( " Number is EVEN " );
}
else
System.out.print("Number is ODD");
}
}![]() |
Similar Threads
- Odd And Even (Java)
- Even / Odd code HELP!! (Java)
Other Threads in the Java Forum
- Previous Thread: Single Linked Circular Link List
- Next Thread: how to download a java applet from a website
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database db defaultmethod development dice dragging draw ebook eclipse error event exception formatingtextintooltipjava fractal game givemetehcodez graphics gui html ide image infinite input integer invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx oracle parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






