Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. class FunStrings
  2. {
  3.     public void FunStrings()
  4.     {
  5.     }//FunStrings
  6.     public int rstl(String str)
  7.     {
  8.         int x = 0;
  9.  
  10.  
  11.         int countR=0;
  12.         int countS=0;
  13.         int countT=0;
  14.         int countL=0;
  15.  
  16.         while(x < str.length()&& str.indexOf("r",x)!= -1)
  17.         {
  18.             countR++;
  19.             x=str.indexOf("r",x)+1;
  20.         }//while for r
  21.         x=0;
  22.         while(x < str.length()&& str.indexOf("s",x)!=-1)
  23.         {
  24.             countS++;
  25.             x=str.indexOf("s",x)+1;
  26.         }//while for s
  27.         x = 0;
  28.         while( x< str.length() && str.indexOf("t",x)!=-1)
  29.         {
  30.             countT++;
  31.             x=str.indexOf("t",x)+1;
  32.         }//while for t
  33.         x = 0;
  34.         while(x < str.length()&& str.indexOf("l",x)!=-1)
  35.         {
  36.             countL++;
  37.             x=str.indexOf("l",x)+1;
  38.         }//while for l
  39.         return countR + countS + countT + countL;
  40.     }
  41.     public boolean evenOdd(int num)
  42.     {
  43.         int rem;
  44.         rem = num % 2;
  45.         if(rem==1)//to determine remainder
  46.         {
  47.             return false;
  48.         }else{
  49.             return true;
  50.         }//It is Even
  51.     }
  52.     public void Song(int lines)
  53.     {
  54.         int lineNum = 100;
  55.         for(int ln=0;ln<lines;ln++)
  56.         {
  57.             System.out.println(lineNum + " lines of code in the program.");
  58.             System.out.println(lineNum + " lines of code...");
  59.             System.out.println("If one line has an error...");
  60.             lineNum--;
  61.             System.out.println(lineNum + " lines of code in the program.");
  62.             System.out.println();
  63.         }//For Loop for line count of song.
  64.     }
  65.  
  66.     public boolean palindrome(String str)
  67.     {
  68.          str = str.toUpperCase();
  69.          String forward ="", backward="";
  70.          for (int x=0; x < str.length();x++)
  71.             if (!str.substring(x,x+1).equals(" "))
  72.                 forward += str.substring(x,x+1);
  73.          for (int x=forward.length()-1; x>=0; x--)
  74.                 backward += forward.substring(x,x+1);
  75.          Util.SOPL(forward + " " + backward);
  76.          return backward.equals(forward);
  77.     }//palindrome
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement