0

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

6
Contributors
7
Replies
16
Views
12 Years
Discussion Span
Last Post by new_programmer
0

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

0

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

Edited by happygeek: fixed formatting

0

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

Edited by happygeek: fixed formatting

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

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

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

Edited by mike_2000_17: Fixed formatting

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.