forked from sonumahajan/All_Program_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenNumberOfDigits.java
More file actions
53 lines (48 loc) · 1.2 KB
/
EvenNumberOfDigits.java
File metadata and controls
53 lines (48 loc) · 1.2 KB
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
46
47
48
49
50
51
52
53
package com.gulraiz;
public class EvenNumberOfDigits {
public static void main(String[] args) {
int[] arr = {12,345,2,6,7896};
System.out.println(findNumbers(arr));
}
// Method-1:
/*
static int findNumbers(int[] nums) {
int evenDigits = 0;
for(int num : nums){
int count = 0;
while(num > 0){
num = num / 10;
count++;
}
if(count % 2 == 0){
evenDigits++;
}
}
return evenDigits;
}
*/
// Method-2:
static int findNumbers(int[] nums) {
int count = 0;
for(int i=0; i<nums.length; i++){
if((nums[i]>9 && nums[i]<100) || (nums[i]>999 && nums[i]<10000) || (nums[i]==100000)){
count++;
}
}
return count;
}
// Method-3:
/*
static int findNumbers(int[] nums) {
int count = 0;
for(int num : nums){
String s = String.valueOf(num);
int len = s.length();
if(len % 2 == 0){
count++;
}
}
return count;
}
*/
}