Write a java program to check palindrome string at least two different vowels

Write a program to check if a given string is palindrome and contains at least two different vowels.

Note Case Insensitive while considering vowel, i.e a & A are the same vowels, But Case sensitive while considering palindrome i.e abc CbA are not palindromes.

Input and Output Format:

Input consists of a string with a maximum size of 100 characters.

Output consists of a single Integer.

Refer sample output for formatting specifications.

Sample Input 1:

abceecba

Sample Output 1:

valid

Sample Input 2:

abcd

Sample Output 2:

Invalid

Java program to check palindrome string at least two different vowels

package testCases;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Scanner;
public class MainJava {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
System.out.println(display(s));
}
 
public static int display(String s) {
StringBuffer sb = new StringBuffer(s);
int k = 0;
LinkedHashSet<Character> l1 = new LinkedHashSet<Character>();
String s2 = sb.reverse().toString();
if (s2.equals(s)) {
String s3 = s2.toLowerCase();
 
for (int i = 0; i < s3.length(); i++) {
l1.add(s3.charAt(i));
}
Iterator<Character> it = l1.iterator();
while (it.hasNext()) {
char a = it.next();
 
if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
k++;
}
}
if (k >= 2)
return 1;
else
return -1;
 
}
 
}

 

Add a Comment

Your email address will not be published. Required fields are marked *

13 − 8 =