Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A program to allow students to try out different
- * String methods.
- * @author Laurie White
- * @version April 2012
- */
- public class StringExplorer
- {
- public static void main(String[] args)
- {
- String sample = "The quick brown fox jumped over the lazy dog.";
- // Demonstrate the indexOf method.
- int position = sample.indexOf("quick");
- System.out.println ("sample.indexOf(\"quick\") = " + position);
- // Demonstrate the toLowerCase method.
- String lowerCase = sample.toLowerCase();
- System.out.println ("sample.toLowerCase() = " + lowerCase);
- System.out.println ("After toLowerCase(), sample = " + sample);
- // Try other methods here:
- int notFoundPsn = sample.indexOf("slow");
- System.out.println("sample.indexOf(\"slow\") = " + notFoundPsn);
- int trial = sample.indexOf("quick", 4);
- System.out.println ("sample.indexOf(\"quick\", 4) = " + trial);
- int trial2 = sample.indexOf("quick", 6);
- System.out.println ("sample.indexOf(\"quick\", 6) = " + trial2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement