178k views
2 votes
What is written to the monitor by the following section of code:

String strA;
String strB = new String("Cheese");
System ( strB );
strA = new String(" Whizz");
System.out.println( strA );

User Viktoriya
by
8.5k points

1 Answer

4 votes

Final answer:

The corrected code outputs two lines: 'Cheese' and ' Whizz'. The error in the initial code has been corrected to use System.out.println for proper syntax in Java.

Step-by-step explanation:

The code provided is in Java, and it appears there is an issue with the syntax in the given code fragment. The correct way to output a string to the console in Java is using System.out.println. Assuming 'System ( strB );' is a typo and should be 'System.out.println( strB );', the first line of output would be 'Cheese', followed by the second output ' Whizz' (with a space before Whizz). The complete outputs would be:

  • cheese
  • whizz

The print method displays the value of the argument provided to it. In this case, it will output the values assigned to strB and strA respectively.

User Jeanmichel
by
8.0k points