Define a class to accept and store 10 strings into the array and print the strings with even number of characters.
Answers
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]);
}
}
}
}
Explanation:
Answer:
import java.util.Scanner;
public class KboatSDAPalindrome
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String words[] = new String[10];
System.out.println("Enter 10 words:");
for (int i = 0; i < words.length; i++) {
words[i] = in.nextLine();
}
System.out.println("\nPalindrome Words:");
for (int i = 0; i < words.length; i++) {
String str = words[i].toUpperCase();
int strLen = str.length();
boolean isPalin = true;
for (int j = 0; j < strLen / 2; j++) {
if (str.charAt(j) != str.charAt(strLen - 1 - j)) {
isPalin = false;
break;
}
}
if (isPalin)
System.out.println(words[i]);
}
}
}