Check the number as Even or Odd without using % or / operator in Java.

import java.util.Scanner;

public class EvenOdd{

public static void main(String [] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int number=sc.nextInt();
if((number &1)==0){
System.out.println("Even number");
}
else{
System.out.println("Odd number");
}
}

}

Output: Enter the number: 6
Even number.



Comments

Popular posts from this blog

Reasoning-Number Series

Reasoning-Letter Series

Multiply Negative numbers in java