✕ Close

Week 14 · 14.3 · Thu, Nov 5 · Do Now

Do Now

Work every question in your notebook. Do it on your Chromebook with your ID.

  1. Where it starts

    Which line runs first?

    public class Main
    {
        public static void intro()
        {
            System.out.println("welcome");
        }
    
        public static void extra()
        {
            System.out.println("bonus");
        }
    
        public static void main(String[] args)
        {
            System.out.println("play");
        }
    }
    1. line 1
    2. line 5
    3. line 13
    4. line 15
  2. Predict

    What does this print? The first line printed is first.

    int y = 4;
    y = y + 6;
    y = y * 2;
    System.out.println(y);
    y = y - 5;
    System.out.println(y);
    1. 20, then 15
    2. 15, then 15
    3. 14, then 9
    4. 20, then 20
  3. Error analysis

    A student says this program prints Lunch and then Class. It prints only Class. What mistake did the student make?

    public class Main
    {
        public static void bell()
        {
            System.out.println("Lunch");
        }
    
        public static void main(String[] args)
        {
            System.out.println("Class");
        }
    }
    1. The student ran bell, but main never calls bell.
    2. The student started at line 10 instead of line 1.
    3. The student forgot that println prints on its own line.
    4. The student ran the statements from the bottom up.
  4. Order matters

    A program stores 3 in m. Which order of the next two statements makes it print 10?

    1. m = m * 3; then m = m + 1;
    2. m = m + 1; then m = m * 3;
    3. either order prints 10
    4. m = m * 3; only
  5. Output

    Write exactly what this program prints, one line for each print.

    public class Main
    {
        public static void main(String[] args)
        {
            System.out.println("up");
            turn();
            System.out.println("down");
        }
    
        public static void turn()
        {
            System.out.println("around");
        }
    }
  6. Turn and Talk, Part 1: What went wrong?

    Turn and Talk · Part 1 · talk with your partner first.

    • “I think the mistake is in line ___ because ___.”
    • “I agree / disagree, because ___.”

    A student wrote down what the screen shows. Talk with your partner: what went wrong?

    public class Greet
    {
        public static void main(String[] args)
        {
            System.out.print("Hi");
            System.out.println("there");
            System.out.println("Sam");
        }
    }
    The student's screen
    LineShown
    1Hi
    2there
    3Sam
    1. print does not end the line, so Hi and there share line 1
    2. println never ends the line
    3. Sam should come first
    4. The quotation marks show on the screen
  7. Turn and Talk, Part 2: Is it right now?

    Turn and Talk · Part 2 · talk with your partner first.

    • “I think it is right now, because ___.”
    • “I think it is still wrong at line ___, because ___.”

    The student fixed line 1. Is it right now?

    public class Greet
    {
        public static void main(String[] args)
        {
            System.out.print("Hi");
            System.out.println("there");
            System.out.println("Sam");
        }
    }
    The student's new screen
    LineShown
    1Hi there
    2Sam
    1. Still wrong: there is no space, so line 1 is Hithere
    2. Right: line 1 is Hi there
    3. Still wrong: Sam belongs on line 1 too
    4. Still wrong: there are 3 lines