StringPractice2 Class

 

import java.util.Scanner;

public class StringPractice2 {

/** Your Name Here
* String Practice
* Two things to remember about Strings
* 1. Strings are Objects, they are NOT primitives like int, double or boolean
* 2. Strings are IMMUTABLE - you cannot modify a String object,
* instead a new String object is created
*/

public static void main(String[] args) {
// Part 1
System.out.println("Part 1");
Scanner reader= new Scanner(System.in); // create a scanner object to get user input.
String lineOfText = "This is one line of text."; // declare two String objects
System.out.println("When I use the .length() method on \"This is one line of text.\" here is what I get: " + lineOfText.length());
System.out.println("Does this include spaces as characters?");
System.out.println("When I use the .substring(8) method on \"This is one line of text.\" here is what I get: " + lineOfText.substring(8));
System.out.println("What does the 8 determine?");
System.out.println("What happens if I change the 8 t0 35?");
System.out.println("When I use the .indexOf(\"one\") method on \"This is one line of text.\" here is what I get: " + lineOfText.indexOf("one"));
System.out.println("Why is the answer 8 and not 9?");
System.out.println("When I use the .indexOf(\"i\") method on \"This is one line of text.\" here is what I get: " + lineOfText.indexOf("i"));
System.out.println("What would I have to do if I wanted to count all of the \"i\"s in this line of text?");
reader.close();

}
}