CS 46A - Lecture 3

Cover page image

Pre-class reading

Algorithms

Pseudocode

Program Development Process

Program Development Process

Types

Number Literals

Number Literals

Number Types

Lecture 3 Clicker Question 1

What is the type of the values 0, 0.0, and "0"?

  1. int, double, string
  2. int, float, string
  3. primitive, primitive, object
  4. None of the above

Variables

Variable Declarations

Variable Declarations

Identifiers

Syntax 2.1 Variable Declaration

Variable Declaration

Variable Names

Variable Names

Lecture 3 Clicker Question 2

How many of the following are legal identifiers?

Greeting1
g
void
101dalmatians
Hello, World
<greeting>
  1. one of them
  2. two of them
  3. three of them
  4. four of them

The Assignment Operator

int width = 10;
      

The Assignment Operator

int width = 10;
width = 20;

Uninitialized Variables

Syntax 2.2 Assignment

Assignment

Assignment

Lecture 3 Clicker Question 3

What is the value of x and y after the following statements?

double x = 10;
double y = 2 * x;
x = 2 * y;
y = 2 * y;
  1. x = 10, y = 20
  2. x = 20, y = 40
  3. x = 40, y = 40
  4. x = 40,  y = 80

Lecture 3 Clicker Question 4

Suppose you have a variable

String greeting = "Hello, World!";

How do you change the value of the greeting variable to "Hello, Nina!"?

  1. greeting = "Hello, Nina!";
  2. String greeting = "Hello, World!";
  3. greeting.changeTo("Hello, Nina!");
  4. greeting.substring(6, 11) = "Nina";