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

Fill in the blanks in the program below as follows: (a) declare the variable tow

ID: 3631681 • Letter: F

Question

Fill in the blanks in the program below as follows:
(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)
// **************************************************
// StringPlay.java
//
// Play with String objects
// **************************************************
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);
}
}


Some sample output would look like this:
PoDunk College contains 14 characters.
The final string is PoDunk CollegeAnytown, USA

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote