public class Questions1_4 { public static void main(String[ ] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } }


Use the following class definition to answer questions 1-4.

public class Questions1_4

{

public static void main(String[ ] args)

{

System.out.print("Here");

System.out.println("There " + "Everywhere");

System.out.println("But not" + "in Texas");

}

}

1) The program will print the word "Here" and then print


a) "There Everywhere" on the line after "Here"

b) "There" on the line after "Here" and "Everywhere" on the line after "There"

c) "There Everywhere" on the same line as "Here"

d) "ThereEverywhere" on the same line as "Here"

e) "ThereEverywhere" on the line after "Here"

Answer: c. Explanation: System.out.print will output the word "Here" but will leave the cursor at that point rather than starting a new line. The next statement will output "There Everywhere" immediately after the word "Here". Since there is a blank space within the quote marks for "There", there is a blank space inserted between "There" and "Everywhere".

2) The final println command will output


a) "But not in Texas"

b) "But notin Texas"

c) "But not" on one line and "in Texas" on the next line

d) "But not+in Texas"

e) "But not + in Texas"

Answer: b. Explanation: The “+” performs String concatenation, so that "But not" and "in Texas" are concatenated together. Notice that there is no blank space after "not" or before "in" so that when they are concatenated, they are placed together without a blank space.

3) How many lines of output are provided by this program?


a) 1

b) 2

c) 3

d) 4

e) 5

Answer: b. Explanation: There will be one line of output for the first two statements combined because the print statement does not return the cursor to start a new line. And since the second statement is a println, it returns the cursor and the last println outputs its message on a separate line.

4) A reasonable comment for this program might be


a) // a program that demonstrates the differences between print, println and how + works

b) // a program that outputs a message about Texas

c) // a program that demonstrates nothing at all

d) // a program that outputs the message “Here There Everywhere But not in Texas”

e) // a program that has three output statements in it

Answer: a. Explanation: Remember that comments should not state the obvious (ruling out d and e) but instead should explain what the program is doing or why. This program demonstrates print and println and +.