-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList_Elements_Check.java
More file actions
38 lines (34 loc) · 921 Bytes
/
ArrayList_Elements_Check.java
File metadata and controls
38 lines (34 loc) · 921 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
28
29
30
31
32
33
34
35
36
37
38
// In an array or arraylist checking the number of element has even number of digits or not.
package technicals;
import java.util.*;
public class Check {
static int even(ArrayList<Integer> list)
{
int count=0;
for(int ele:list)
{
int numdigit=digit(ele);
if(numdigit%2==0)
count++;
}
return count;
}
static int digit(int number)
{
return ((int)Math.log10(number)+1);//we can count the number of digit with this method also
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements in the list");
int a =sc.nextInt();
ArrayList<Integer>list = new ArrayList<>();
System.out.println("Enter the elements in the list");
for(int i =0;i<a;i++)
{
list.add(sc.nextInt());
}
System.out.println(list);
int c=even(list);
System.out.println("Number of even number of digits eleemnt is :"+c);
}
}