| | |
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 |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui homework html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql sqlite static stop string swing testautomation threads time tree ui unicode validation windows






