24su ver.

Note: this is for the Summer 2024 iteration of CSE 121. Looking for a different quarter? Please visit https://courses.cs.washington.edu/courses/cse121/.

Escape Sequences

Sequence Description
\t tab
\n new line
\" quotation mark
\\ backslash

Data Types

Type Description Examples
int integers, numbers without fractional components 42, -3, 92851
double decimal numbers 3.14, 2.0
String text "Hello", "CSE 121"
boolean logical values true, false

Expressions

  • Precedence: () before * / % before + -
  • with int, / is integer division and % is integer remainder
  • Strings can be concatenated with other values
Example with integers
For the expression 1 times 2 plus 3 times 5 divided by 4, we start off by evaluating 1 times 2, which evaluates to 2, leaving us with the expression 2 plus three times 5 divided by 4. We then evaluate 3 times 5, which is 15, leaving us with the expression 2 plus 15 divided by 4. Then, we evaluate 15 divided by 4, which gives us 3, leaving us with the expression 2 plus 3, which evaluates to 5.
Example with Strings and doubles
For the expression, double quote $ double quote plus 9.0 divided by 4.0 plus 1, we first perform 9.0 divided by 4.0, which is 2.25, giving us a the resulting expression double quote $ double quote plus 2.25 plus 1. We then evaluate double quote $ double quote plus 2.25, which is double quote dollar sign 2.25 double quote, leaving us with the expression double quote dollar sign 2.25 double quote plus 1, which results in double quote dollar sign 2.251 double quote.

Arithmetic Operators

(Compute a value using arithmetic operations)

Operator Meaning
+ addition
- subtraction, negation
* multiplication
/ division
% remainder (“modulus”)

Relational Operators

Operator Description
< less than
<= less than or equal
> greater than
>= greater than or equal
== equal
!= not equal

Logical Operators

(Evaluate expressions as true or false)

Operator Description
&& and
|| or
! not

Truth Table for &&

Expression Result
true && true true
true && false false
false && true false
false && false false

Truth Table for ||

Expression Result
true || true true
true || false true
false || true true
false || false false