Even Odd Checker
Problem Statement
1Problem Description :2Write Java Program to check whether a given integer is Even or Odd34Example 1 :56 Input : 277 Output : Odd8 Explanation : 27 divide by 2 results remainder as 1.910Example 2 :1112 Input : 3613 Output : Even14 Explanation : 36 divide by 2 results remainder as 0.
Algorithm
1Step 1 : Start2Step 2 : Read number "n"3Step 3 : rem = n % 2 (Initialize remainder as rem)4Step 4 : If rem = 0, print Even5Step 5 : Else print Odd.6Step 6 : End
Flowchart
Code Implementation
- Java
- C
1import java.util.Scanner;23public class EvenOdd {45 public static void main(String[] args) {6 Scanner sc = new Scanner(System.in);7 System.out.println("Enter Number :");8 int number = sc.nextInt();910 int rem = number % 2 ;11 if (rem == 0) {12 System.out.printf("%d is Even\n", number);13 }else {14 System.out.printf("%d is Odd\n", number);15 }16 }17}
Output 1:
1Enter Number : 21221 is Odd
Output 2:
1Enter Number : 18218 is Even