Write a program to check if a given string is palindrome and contains at least two different vowels.
The return type (integer) should be 1 if the above condition is satisfied, otherwise return -1.
NoteCase Insensitive while considering vowel, i.e a & A are 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 maximum size of 100 characters.
The 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
import java.util.Scanner; import java.util.Iterator; import java.util.LinkedHashSet; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); System.out.println(display(s)); } public static String 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 "Valid"; else return "Invalid"; } }