-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab21.java
More file actions
29 lines (27 loc) · 887 Bytes
/
Copy pathjavalab21.java
File metadata and controls
29 lines (27 loc) · 887 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
import java.util.*;
public class javalab21 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList <String> List = new ArrayList<>();
System.out.print("Enter number of elements in the string type List: ");
int n = sc.nextInt();
String st;
sc.nextLine();
for(int i = 0;i < n; i++){
System.out.println(" Enter element " + (i+1) + ":");
st = sc.nextLine();
List.add(st);
}
removeEvenLength(List);
System.out.println("List after removal of even length element: ");
System.out.println(List);
}
static void removeEvenLength(ArrayList<String> list){
for(int i = 0;i < list.size(); i++){
if(list.get(i).length()%2==0){
list.remove(i);
i--;
}
}
}
}