Question
1. Fill in the blanks in the StringPlay.java program (Section 3.2, especially the example in Listing 3.1, should be helpful): (a) declare the variable town
1. Fill in the blanks in the StringPlay.java program (Section 3.2, especially the example in Listing 3.1, should be helpful):
(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)
1 1/ ******** 2 1/ StringPlay.java 3 // 4 // Play with String objects 5 // ***** 6 public class StringPlay 7 { 80 public static void main (String[] args) 9 { 10 String college = new String ("PoDunk College"); 11 -; // part (a) 12 int stringLength; 13 String changei, change2, change3; 14 -; // part (b) 15 System.out.println (college + contains + stringLength + " characters."); 16 changel = .; // part (c) 17 change2 = ; // part (d) 18 change3 = ; // part (e) 19 System.out.println ("The final string is " + change3); 20 } 21 } 22 11Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started