954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Odd/Even Code

Hello,
I am having trouble with my Odd/ Even Code. Can anyone help me with this? Or has a current code?

Babyblues
Newbie Poster
3 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

where is your odd/even code ... let us have a look over it. Only then we'll be able to help you.

nanosani
Unauthenticated Liar
Team Colleague
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
 

[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 " );

Babyblues
Newbie Poster
3 posts since Sep 2004
Reputation Points: 10
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 " );


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

DoubleShot
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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");
   }
}
nanosani
Unauthenticated Liar
Team Colleague
1,830 posts since Jul 2004
Reputation Points: 45
Solved Threads: 56
 

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 :
+
++
+++
++++
+++++
++++
+++
++
+

alreem
Newbie Poster
24 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

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.");
}
}
}

hahahha
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Number;

public class OddEven{

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

		String strNumber;
		int number=2;
		System.out.println("Enter a number:");
		strNumber = bufRead.readLine();
		number = Integer.parseInt(strNumber);


		if (number % 2 == 0)
		{
			System.out.println(" Even Number Entered is : "+number);

			for(int i=0; i < number ; i++)
			{
				for(int j=0 ; j< i ; j++)
				{
					System.out.print("+");
				}
			System.out.println("");
			}

			for(int i=number ; i >0 ; i--)
			{
				for(int j=i ; j >0 ; j--)
				{
					System.out.print("+");
				}
			System.out.println("");
			}

		}
		else
		{
			System.out.println(" Odd Number Entered is : "+number);
			for(int i=0; i < number ; i++)
			{
				for(int j=0 ; j< i ; j++)
				{
					System.out.print("+");
				}
			System.out.println("");
			}

			for(int i=number ; i >0 ; i--)
			{
				for(int j=i ; j >0 ; j--)
				{
					System.out.print("+");
				}
			System.out.println("");
			}

		}
	System.out.println("------------------Thank You --------------------------------");
	}
}

new_programmer

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

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You