can someone help me w/ this?! how to evaluate the EVEN or ODD..all EVEN numbers should store on arrayEven variable,while all ODD numbers store on arrayOdd variable..

import java.util.Scanner;
import java.util.Arrays;

public class online1{
public static void main(String args[]){


int SIZE= 10;

int []number = new int[SIZE];

Scanner input = new Scanner(System.in);


for(int index=0; index<SIZE; index++)
{
System.out.print("Enter Integer Number: ");
number[index] = input.nextInt();
}




System.out.println();
Arrays.sort(number);

System.out.print("arrayNumber: ");
for(int index=0;index<SIZE;index++)
System.out.print(" "+ number[index]);
System.out.println();


} 
}

Let's say X is your number.
If X is even, then it must be divisible by 2 OR it's equal to zero. If it isn't then it's not even.

You would use something along these lines to determine whether or not your number is even.

In this, X is the number that you are evaluating.

public class Parity {
public static int x;

	public static void determineParity() {
		if (x%2 == 0 || x == 0) {
			// X must be even, so put your even-number code here.
		} else {
			// X must be odd, so put your odd-number code here.
		}
	}
}

You would use something similar to this to determine the parity (odd/even) of your number.

FYI, if x is 0 then x % 2 is also 0. The second check is worthless.

Member Avatar for sravan953

Here, try this:

import java.io.*;
class even_or_odd
{
static void check()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter a number to check if it is even or odd: ");
        int x=Integer.parseInt(br.readLine());
        if(x==0)
        System.out.println(x+" is even.");
        else if(x%2==0)
        System.out.println(x+" is even.");
        else if(x%2!=0)
        System.out.println(x+" is odd.");
    }
}

Modify a little more to store it an array! ;)

Here, try this:

import java.io.*;
class even_or_odd
{
static void check()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter a number to check if it is even or odd: ");
        int x=Integer.parseInt(br.readLine());
        if(x==0)
        System.out.println(x+" is even.");
        else if(x%2==0)
        System.out.println(x+" is even.");
        else if(x%2!=0)
        System.out.println(x+" is odd.");
    }
}

Modify a little more to store it an array! ;)

Like masijade said, if x== 0, then x % 2 == 0. The check for x == 0 is unnecessary. The final "else if" can be changed to an "else", though I don't imagine it helps efficiency all that much. It probably doesn't take much to evaluate x % 2 and compare it to 0. Still, why do it twice?

FYI, if x is 0 then x % 2 is also 0. The second check is worthless.

Right. Sorry, I'm just not sure how Java evaluates modulus because for whatever reason my calculator won't perform modulus on zero. I guess it's just me.

..thanks for all your replies ..it really helps me a lot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.