Advertisement
StefanTobler

TERM 2 StringExplorer

Jan 19th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. /**
  2.  * A program to allow students to try out different
  3.  * String methods.
  4.  * @author Laurie White
  5.  * @version April 2012
  6.  */
  7. public class StringExplorer
  8. {
  9.  
  10.  public static void main(String[] args)
  11.  {
  12.   String sample = "The quick brown fox jumped over the lazy dog.";
  13.  
  14.   //  Demonstrate the indexOf method.
  15.   int position = sample.indexOf("quick");
  16.   System.out.println ("sample.indexOf(\"quick\") = " + position);
  17.  
  18.   //  Demonstrate the toLowerCase method.
  19.   String lowerCase = sample.toLowerCase();
  20.   System.out.println ("sample.toLowerCase() = " + lowerCase);
  21.   System.out.println ("After toLowerCase(), sample = " + sample);
  22.  
  23.   //  Try other methods here:
  24.  
  25.   int notFoundPsn = sample.indexOf("slow");
  26.   System.out.println("sample.indexOf(\"slow\") = " + notFoundPsn);
  27.  
  28.   int trial = sample.indexOf("quick", 4);
  29.   System.out.println ("sample.indexOf(\"quick\", 4) = " + trial);
  30.  
  31.   int trial2 = sample.indexOf("quick", 6);
  32.   System.out.println ("sample.indexOf(\"quick\", 6) = " + trial2);
  33.  }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement