Wednesday, 15 July 2015

Java Programs Made Easy

Q)... Check whether a given string is palindrome also check whether it has atleast 2 different vowels
input: "madam"
output: false(no 2 diff vowels)



  1. package Set1;
  2. public class ClassSet25 {
  3.  public static boolean palindromeAndVowelCheck(String s){
  4.   boolean b=true;
  5.   int c=0;
  6.   String s1="aeiou";
  7.   StringBuffer sb=new StringBuffer(s);
  8.   String s2=sb.reverse().toString();
  9.   if(!s2.equals(s))
  10.    b=false;
  11.   else{
  12.   loop:
  13.   for(int i=0;i<s1.length();i++)
  14.    for(int j=0;j<s.length();j++)
  15.     if(s1.charAt(i)==s.charAt(j)){
  16.      c++; 
  17.      continue loop; }
  18.   if(c<2)
  19.    b=false;
  20.   } 
  21.   return b;
  22.  }
  23. public static void main(String[] args) {
  24.   String s="deed";
  25.   System.out.println(palindromeAndVowelCheck(s));
  26.  }
  27. }