Write a java program to check Palindrome & Vowels

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:


Sample Output 1:


Sample Input 2:


Sample Output 2:


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();

  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++) {

      Iterator<Character> it = l1.iterator();
      while (it.hasNext()) {
        char a = it.next();

        if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
    if (k >= 2)
      return "Valid";
      return "Invalid";


Add a Comment

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

13 + nine =