-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddOrEven.java
More file actions
27 lines (21 loc) · 753 Bytes
/
OddOrEven.java
File metadata and controls
27 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This program checks if a number is odd or even using bitwise operations.
// Description: A program that checks if a number is odd or even using bitwise operations.
// It reads an integer from input and prints "Odd" if the number is odd, and "Even" if the number is even.
//
// Example Input/Output:
// Input: 5
// Output: Odd
// Input: 4
// Output: Even
import java.util.*;
public class OddOrEven {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt(); // Read an integer from input
if ((num & 1) == 0) {
System.out.println("Even"); // If the number is even
} else {
System.out.println("Odd"); // If the number is odd
}
}
}