-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountEvenNumber.java
45 lines (35 loc) · 889 Bytes
/
CountEvenNumber.java
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// COUNT EVEN NUMBER
// TAKE A INT NUMBER FROM USER PRINT THE NUMBER OF EVEN DIGITS IF IT IS GREATER THAN 3 OTHER THAN PRINT " IT IS NOT A VALID NUMBER "
// INPUT
// 4536782
// OUTPUT
// 4
// INPUT
// 1365279
// OUTPUT
// IT IS NOT A VALID NUMBER
package TCSEXPLORE;
import java.util.Scanner;
public class CountEvenNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number : ");
int number = sc.nextInt();
int count = 0, rem = 0;
while (number > 0) {
rem = number % 10;
number = number / 10;
if (rem % 2 == 0) {
count++;
}
}
if (count > 3) {
System.out.println(count);
} else {
System.out.println("IT IS NOT A VALID NUMBER");
}
}
}
// How To Run The package code
// javac -d . CountEvenNumber.java
// java TCSEXPLORE.CountEvenNumber