?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Printing an Address Using Variables

APCSA-6LEGXK

Consider the following declared variables.

String firstName = "John";
String lastName = "Doe";
String street = "100 Main Street";;
String city = "Charlotte";
String state = "NC";
int zip = 28205;

Which of the following code segments will print the address in this format?

John Doe
100 Main Street
Charlotte, NC 28205

I.

System.out.println(firstName + " " + lastName);
System.out.println(street);
System.out.println(city + ", " + state + " " + zip);

II.

System.out.print(firstName);
System.out.print(" ");
System.out.println(lastName);
System.out.println(street);
System.out.print(city);
System.out.print(", ");
System.out.print(state);
System.out.print(" ");
System.out.println(zip);

III.

System.out.print(firstName + " " + lastName);
System.out.print(street);
System.out.print(city + ", " + state + " " + zip);

IV.

System.out.print(firstName + " " + lastName + "\n" + street + "\n" + city + ", " +  state + " " + zip);
A

I and II only.

B

I, II, and IV only.

C

II, III, and IV only.

D

II and III only.

E

I, II, III, and IV.