Do you think that the following is correct?
str1.length() = 12 ; // change the length of str1
No. The left-hand side of an assignment statement must be a variable.
If you got this question wrong, review the two steps of an assignment statement (on the previous page.)
It has been a long time since you have had some blue blanks to fill in. I'm sure that you have missed them. Here is a program that will:
class StringTester { public static void main ( String[] args ) { String str1; // str1 is a reference to a String object. ______ ____; // str2 is a reference to a second String object. int ______ , ______ ; // the length of str1 and the length of str2 ____ = _________________________ ; // create the first String ____ = _________________________ ; // create the second String _____ = str1.length(); // get the length of the first string _____ = ____.________; // get the length of the second string System.out.println("The combined length of both strings is " + _________________ + " characters" ); } } |