Odd/Even Code

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 3
Reputation: Babyblues is an unknown quantity at this point 
Solved Threads: 0
Babyblues Babyblues is offline Offline
Newbie Poster

Odd/Even Code

 
0
  #1
Sep 7th, 2004
Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this? Or has a current code?
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Odd/Even Code

 
0
  #2
Sep 8th, 2004
where is your odd/even code ... let us have a look over it. Only then we'll be able to help you.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 3
Reputation: Babyblues is an unknown quantity at this point 
Solved Threads: 0
Babyblues Babyblues is offline Offline
Newbie Poster

Re: Odd/Even Code

 
0
  #3
Sep 9th, 2004
[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 " );
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8
Reputation: DoubleShot is an unknown quantity at this point 
Solved Threads: 0
DoubleShot DoubleShot is offline Offline
Newbie Poster

Re: Odd/Even Code

 
0
  #4
Sep 9th, 2004
[QUOTE=Babyblues]
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Odd/Even Code

 
0
  #5
Sep 10th, 2004
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");
   }
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 17
Reputation: alreem is an unknown quantity at this point 
Solved Threads: 0
alreem alreem is offline Offline
Newbie Poster
 
0
  #6
32 Days Ago
Can any one help me Plz
- write an java program that outputs the followingpattern. Th program should prompt the user an osdd nmbr of lines (limit 1 to 11).
For example, if the user prompt the number of lines is 9, the the outputs should be :
+
++
+++
++++
+++++
++++
+++
++
+
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC