25wi ver.
Note: this is for the Winter 2025 iteration of CSE 121. Looking for a different quarter? Please visit https://courses.cs.washington.edu/courses/cse121/.
(DO NOT WRITE ANY WORK YOU WANTED GRADED ON THIS REFERENCE SHEET. IT WILL NOT BE GRADED)
type[] name = new type[length];
type[] name = {VAL1, VAL2, VAL3, ...};
type[][] name = new type[numRows][numColumns];
type[][] name = {
            {VAL1, VAL2, VAL3, ...},
            ...
            {VAL4, VAL5, VAL6, ...}
};
| Using Arrays | Description | 
|---|---|
| int value = name[i] | Get the value at index i | 
| name[i] = value | Set the value at index i | 
| name.length | Get the number of elements in name | 
| Using 2D Arrays (rectangular) | Description | 
|---|---|
| int value = name[i][j] | Get the value at row i, columnj | 
| name[i][j] = value | Set the value at row i, columnj | 
| name.length | Number of rows (number of inner arrays) | 
| name[0].length | Number of columns (length of inner array) | 
| String Method | Description | 
|---|---|
| charAt(i) | Returns character in this String at index i | 
| contains(str) | Returns trueif this String containsstrinside it, returnsfalseotherwise | 
| startsWith(str) | Returns trueif this String starts withstr, returnsfalseotherwise | 
| endsWith(str) | Returns trueif this String ends withstr, returnsfalseotherwise | 
| equals(str) | Returns trueif this String is the same asstr, returnsfalseotherwise | 
| equalsIgnoreCase(str) | Returns trueif this String is the same asstrignoring capitalization, returnsfalseotherwise | 
| indexOf(str) | Returns the first index this String where strbegins, returns-1if not found | 
| length() | Returns the number of characters in this String | 
| replace(str, newStr) | Returns a new String with all strin this String replaced withnewStr | 
| substring(i) | Returns characters in this String from index i(inclusive) to end (exclusive) | 
| substring(i, j) | Returns characters in this String from index i(inclusive) toj(exclusive) | 
| toLowerCase() | Returns an all-lowercase version of this String | 
| toUpperCase() | Returns an all-uppercase version of this String | 
| Random Method | Description | 
|---|---|
| nextInt(max) | Returns a random integer from 0 (inclusive) to max(exclusive) | 
| nextInt(min, max) | Returns a random integer from min(inclusive) tomax(exclusive) | 
| Math Method | Description | 
|---|---|
| Math.abs(val) | Returns the absolute value of val | 
| Math.max(val1, val2) | Returns the larger of the two values val1andval2 | 
| Math.min(val1, val2) | Returns the smaller of the two values val1andval2 | 
| Math.pow(base, exp) | Returns the value of baseraised to theexppower | 
| Math.sqrt(val) | Returns the square root of val | 
| Scanner Method | Description | 
|---|---|
| next() | Returns the next token as a String | 
| nextLine() | Returns the entire line as a String | 
| nextInt() | Returns the next token as an int, throws exception if cannot | 
| nextDouble() | Returns the next token as a double, throws exception if cannot |