Introduction to CS 159

Nathan Sprague

Spring 2021

Me

CS 159

Mechanics

Facts about CS 159

Looking Ahead: Programming Assignments

Academic Integrity

Getting Help

Questions???

Peer Instruction Ground-Rules:

Socrative Warm-Up #1

What will be printed when the following code segment executes?

Person bob = new Person("Bob");
Person jane = bob;
jane.setName("Jane");
System.out.println(bob.getName());
  1. “Bob”
  2. “Jane”
  3. Nothing: There will be a NullPointerException

Socrative Warm-Up #2

What will be printed when the following code segment executes?

String s1 = "Hello There!";
String s2 = "Hello";
String s3 = s2 + " There!";
if (s1 == s3) {
    System.out.println(s1);
} else {
    System.out.println(s2);
}
  1. “Hello”
  2. “Hello There”
  3. " There"

Socrative Warm-Up #3

How many times will the body of the following for-loop be executed?

for (int i = 0; i <= 10; i += 2) {
    //do something
}
  1. 0
  2. 2
  3. 4
  4. 5
  5. 6
  6. 10
  7. 11

Socrative Warm-Up #4

Assuming values contains {3, 1, 4, 2}, what will v contain after the code segment below executes?

int v = values[0];
for (int i = 1; i < values.length; i++) {
    if (v < values[i]) {
        v = values[i];
    }
}
  1. 1
  2. 2
  3. 2.5
  4. 3
  5. 4

For Friday