16.4k views
20 votes
Define a class in Java to accept and store the list of 10 names in an array. Print the

names with even number of characters.

User Ardhi
by
3.7k points

1 Answer

7 votes

Answer:

public class Main

{

public static void main(String[] args) {

String[] strs = new String[10];

java.util.Scanner sc = new java.util.Scanner(System.in);

for(int i = 0; i < 10; i++){

System.out.print("Enter string " + (i+1) + ":");

strs[i] = sc.nextLine();

}

System.out.println("The strigs with even number of characters is");

for(int i = 0; i < strs.length;i++){

if(strs[i].length() % 2 == 0){

System.out.println(strs[i]);

}

}

}

}

Step-by-step explanation:

User Spencer Sutton
by
3.6k points