MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / EvenOdd

Class EvenOdd

Java/EvenOddNumberUsingBitwiseAnd.java:2–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.Scanner;
2public class EvenOdd {
3 public static void main(String[]args){
4 Scanner sc = new Scanner(System.in);
5 System.out.println("enter the number");
6 int num = sc.nextInt();
7 // using bitwise and operation
8 /* when we convert any decimal number to binary the least significant bit or the last bit if it is 0 -> then it is
9 a even number and if the last bit is 1 it is a odd number. */
10 if((num&1) == 0){
11 System.out.println("even number");
12 }else{
13 System.out.println("odd number");
14 }
15 }
16}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected