Do you think that the following is correct?
str1.length() = 12 ; // change the length of str1
No. The left side of an assignment statement must be a variable.
It has been a long time since you have had some blanks to fill in. I'm sure that you have missed them. Here is a program that will:
String
objectsString
will hold the characters "Green eggs"String
will hold the characters " and ham" class StringTester { public static void main ( String[] args ) { String str1; // a reference to a String object. String str2; // a reference to a second String object. int len1, len2; // the length of str1 and the length of str2 str1 = ; // create the first String str2 = ; // create the second String len1 = str1.length(); // get the length of the first string len2 = . ; // get the length of the second string System.out.println("The combined length of both strings is " + + " characters" ); } }
Fill in the blanks of the program.