Skip to main content

Section 4.16 Assessment: String methods

Subgoals for using objects (creating instances).

  1. Declare variable of appropriate class datatype.
  2. Assign to variable: keyword new, followed by class name, followed by ().
  3. Determine whether parameter(s) are appropriate (API)
    1. Number of parameters
    2. Data types of the parameters

Exercises Exercises

    1.

    Q1: What is the output of the following code?
    String temp = "abcde";
    System.out.println(temp.length());
    

    2.

    Q2: What is the output of the following code?
    String temp = "abcdefghijklmnopqrstuvwxyz";
    System.out.println(temp.indexOf("fgk"));
    

    3.

    Q3: What is the output of the following code?
    String temp = "catcatcat";
    System.out.println(temp.indexOf("cat"));
    

    4.

    Q4: What is the output of the following code?
    String temp = "abcdefghijklmnopqrstuvwxyz";
    System.out.println(charAt.indexOf(3));
    

    5.

    Q5: What is the output of the following code?
    String temp = "onetwothreefour";
    System.out.println(temp.substring(3,6));
    

    6.

    Q6: What is the output of the following code?
    String temp = "onetwothreefour";
    System.out.println(temp.substring(6));
    
You have attempted 1 of 2 activities on this page.