Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(A) Declare the variable town as a reference to a String object and initialize i

ID: 3620443 • Letter: #

Question

(A) Declare the variable town as a reference to a String object and initialize it to "Anytown, USA".
(B) write an assignment statement that invokes the length method of the string class to find the length of the college String object and assigns the result to the stringLength variable.
(C) Complete the assignment statement so that change1 contains the same characters as college but all in upper case
(D) complete the assignment statement so that change2 is the same as change1 except all capital O's are replaced with the asterisk (*) character.
(E) complete the assignment statement so that change3 is the concatenation of college and town (use the concat method of the String class rather than the + operator).

public class StringPlay
{
public static void main (String [] args);
{
String college = new String ("PoDunk College");
______________________________________________; // part (a)
int stringLength;
String change1, change2, change3;
______________________________________________; // part (b)
System.out.println (college + " contains " + stringLength + "characters.");

change1= ___________________________________________; // part (c)
change2= ___________________________________________; // part (d)
change3= ___________________________________________; // part (e)

System.out.println ("The final string is " + change3);
}

}

Explanation / Answer

a) String town = "Anytown, USA";
b) stringLength = college.length();
c) college.toUpperCase();
d) change1.replace('O', '*');
e) college + town;