logo

APSU Notes


Quiz 3

Question 1

Given the following statements:

1
2
String total = "five" + "seven";
System.out.println(total);

What is displayed to the screen?

fiveseven

Question 2

Given the following code:

1
2
String greeting = "Hello There!";
System.out.println(greeting.length());

What is displayed to the screen?

12

Question 3

Given the following code:

1
2
String line = "I love lamp.");
System.out.println(line.indexOf("lamp"));

What is displayed to the screen?

7

Question 4

Given the following code:

1
System.out.println("You had me at \"hello\".");

What is displayed to the screen?

You had me at "hello".

Question 5

Given the following code:

1
2
3
4
System.out.print("One");
System.out.println("Two");
System.out.print("Three");
System.out.println("Four");

What is displayed to the screen?

1
2
OneTwo
ThreeFour

Quesiton 6

Given the following declarations:

1
2
Scanner keyboard = new Scanner(System.in);
String word;

Which of the following reads a single words in to the variable word?

word = keyboard.next();

Question 7

Which of the following is used to display formatted output?

System.out.printf

Question 8

Which of the following would be the best name for a variable representing the distance between two points?

distanceBetweenPoint

Question 9

Which of the following is a correct multi-line comment?

1
2
3
4
/*
This is the first line
This is the second line
*/

Question 10:

Which of the following class definitions is correctly indented?

1
2
3
4
5
6
7
8
public class StyleExample
{
    public static void main(String[] args)
    {
        System.out.println("This is an example of good");
        System.out.println("programming style");
    }
}