Friday, 17 July 2015

Java Programming

Q).. find the three consecutive characters in a string. if the string consists any three
   consecutive characters return 1 else return -1
   like AAAxyzaaa will return true.




  1.  
  2. package Set1;
  3. public class ClassSet36 {
  4. public static void main(String[] args) {
  5.       String s1="aaaaxyzAAA";
  6.       boolean b=consecutiveCharactersCheck(s1);
  7.       if(b==true)
  8.             System.out.println("presence of consecutive characters");
  9.       else
  10.             System.out.println("absence of consecutive characters");
  11.       }
  12.  
  13. public static boolean consecutiveCharactersCheck(String s1) {
  14.       boolean b=false;
  15.       int c=0;
  16.       for(int i=0;i<s1.length()-1;i++)
  17.             if((s1.charAt(i+1)-s1.charAt(i))==1)
  18.                         c++;
  19.       if(c>=2)
  20.             b=true;
  21.       return b;
  22. }
  23. }