Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 2.3 KB

File metadata and controls

66 lines (51 loc) · 2.3 KB

CSE 142

Quiz Answers

Week 1

  1. Below is a program, but it is not executable. Explain what executable means, why the program below is not executable, and what you need to add to make it executable?
        public class Hello {
    
        }

The class Hello needs a main method in order for it to be executable, and for it to run in the Java Runtime Environment.

  1. Write an executable program that prints "Hello World!"

    public class Hello {
        public static void main(String[] args) {
           System.out.println("Hello world!");
        }
    }
  2. Describe the errors in the program below.

    public MyProgram {
       public static void main(String[] args) {
           System.out.println("This is a test of the")
           System.out.Println("emergency broadcast system.");
       }
    }

    The errors are, missing the class on the first line; missing the semiconon on the first print statement, and needs a lowercase 'P' on the second print statement.

  3. What is the name of the character shown: \ Backslash

  4. What is the name of the character shown: / Forward slash, also sometimes called 'slash'

  5. Fill in the escape sequence that matches each character described in the table below.

    Escape sequence Description
    \n Newline
    \t Tab
    " Double quote
    \ Backslash
  6. What will be printed to the console when the program below is run?

    System.out.println("\"Quotes\"");

    "Quotes"

  7. What will be printed to the console when the program below is run?

    System.out.println("Slashes \\//");

    Slashes //

  8. Fill in the table below, evaluating the expressions

    Expression What does it evaluate to
    3 + 4 + " 2 + 2" "7 2 + 2"
    4.0 / 2 * 9 / 2 9.0
    8 / 5 + 13 / 2 / 3.0 3.0
    "hello 34 " + 2 * 4 "hello 34 8"