Implement a Java program to accomplish the following task using String and StringBuffer class: 1. To search a word inside a string 2. To search the last position of a substring 3. To compare two strings 4. To print reverse of a string


 class Exp4_2
{
 public static void main(String[] args) 
 {
  String s = "Java is very Simple but Java is confusing...";
  StringBuffer sb = new StringBuffer(s);
  System.out.println("Searching JAVA gives : "+ s.indexOf("Java"));
  System.out.println("Searching last position of Java gives : "+ s.lastIndexOf("Java"));
  System.out.println("Comparing JAVA with Java gives : "+ s.compareTo("JAVA"));
  System.out.println("Reverse : "+ sb.reverse());
 }
}
/*  OUTPUT!!!
Searching JAVA gives : 0
Searching last position of Java gives : 24
Comparing JAVA with Java gives : 32
Reverse : ...gnisufnoc si avaJ tub elpmiS yrev si avaJ
*/
Copyright © LetML. Blogger Templates Designed by OddThemes