44.9k views
4 votes
1. Consider the following code segment.

System.out.print("The ");
System.out.println("Spartans ");
System.out.println("Rule ");
System.out.print("the South Side. ");
What is printed as a result of executing the code segment?
a) The Spartans Rule the South Side.
b) The Spartans
Rule
the South Side.
c) The Spartans
Rule the South Side.
d) The
Spartans
Rule
the South Side.
e) Nothing, this will produce an error.

1 Answer

2 votes

Answer:

The answer to this question is B.

Step-by-step explanation:

The reason that the answer is B is that in Java, using System.out.print() is going to print a line of code (...) and will not exit to a new line of code while System.out.println() will write to the current line (...) then it will escape to a new line of code.

Input:

System.out.print("The "); //Print to current line

System.out.println("Spartans "); // Print to current line then escape to new line

System.out.println("Rule "); // Print to current line then escape to new line

System.out.print("the South Side. "); // Print to current line

Output:

The Spartans

Rule

the South Side.

User Adil Malik
by
5.2k points