944,116 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 31468
  • Java RSS
Sep 7th, 2004
0

Odd/Even Code

Expand Post »
Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this? Or has a current code?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Babyblues is offline Offline
3 posts
since Sep 2004
Sep 8th, 2004
0

Re: Odd/Even Code

where is your odd/even code ... let us have a look over it. Only then we'll be able to help you.
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Sep 9th, 2004
0

Re: Odd/Even Code

[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 " );
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Babyblues is offline Offline
3 posts
since Sep 2004
Sep 9th, 2004
0

Re: Odd/Even Code

[QUOTE=Babyblues]
Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DoubleShot is offline Offline
10 posts
since Sep 2004
Sep 10th, 2004
0

Re: Odd/Even Code

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");
   }
}
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Nov 7th, 2009
0
Re: Odd/Even Code
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 :
+
++
+++
++++
+++++
++++
+++
++
+
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alreem is offline Offline
24 posts
since Nov 2009
Aug 17th, 2010
0
Re: Odd/Even Code
import java.util.*;
import java.io.*;

public class kaze{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

Integer number;
System.out.println("Input A Number:");
number = Integer.parseInt(in.readLine());


if (number % 2 == 0)
{
System.out.println(" Even.");
}
else
{
System.out.println(" Odd.");
}
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hahahha is offline Offline
1 posts
since Aug 2010
Aug 17th, 2010
0
Re: Odd/Even Code
Java Syntax (Toggle Plain Text)
  1. import java.util.*;
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.lang.Number;
  5.  
  6. public class OddEven{
  7.  
  8. public static void main(String[] args)throws Exception{
  9.  
  10. BufferedReader bufRead = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12. String strNumber;
  13. int number=2;
  14. System.out.println("Enter a number:");
  15. strNumber = bufRead.readLine();
  16. number = Integer.parseInt(strNumber);
  17.  
  18.  
  19. if (number % 2 == 0)
  20. {
  21. System.out.println(" Even Number Entered is : "+number);
  22.  
  23. for(int i=0; i < number ; i++)
  24. {
  25. for(int j=0 ; j< i ; j++)
  26. {
  27. System.out.print("+");
  28. }
  29. System.out.println("");
  30. }
  31.  
  32. for(int i=number ; i >0 ; i--)
  33. {
  34. for(int j=i ; j >0 ; j--)
  35. {
  36. System.out.print("+");
  37. }
  38. System.out.println("");
  39. }
  40.  
  41. }
  42. else
  43. {
  44. System.out.println(" Odd Number Entered is : "+number);
  45. for(int i=0; i < number ; i++)
  46. {
  47. for(int j=0 ; j< i ; j++)
  48. {
  49. System.out.print("+");
  50. }
  51. System.out.println("");
  52. }
  53.  
  54. for(int i=number ; i >0 ; i--)
  55. {
  56. for(int j=i ; j >0 ; j--)
  57. {
  58. System.out.print("+");
  59. }
  60. System.out.println("");
  61. }
  62.  
  63. }
  64. System.out.println("------------------Thank You --------------------------------");
  65. }
  66. }


new_programmer
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
new_programmer is offline Offline
53 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: calculatiing ArcCos
Next Thread in Java Forum Timeline: Beginner/Intermediate Projects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC