(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 , column j |
name[i][j] = value | Set the value at row i , column j |
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 true if this String contains str inside it, returns false otherwise |
startsWith(str) | Returns true if this String starts with str , returns false otherwise |
endsWith(str) | Returns true if this String ends with str , returns false otherwise |
equals(str) | Returns true if this String is the same as str , returns false otherwise |
equalsIgnoreCase(str) | Returns true if this String is the same as str ignoring capitalization, returns false otherwise |
indexOf(str) | Returns the first index this String where str begins, returns -1 if not found |
length() | Returns the number of characters in this String |
replace(str, newStr) | Returns a new String with all str in this String replaced with newStr |
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) to j (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) to max (exclusive) |
Math Method | Description |
---|---|
Math.abs(val) | Returns the absolute value of val |
Math.max(val1, val2) | Returns the larger of the two values val1 and val2 |
Math.min(val1, val2) | Returns the smaller of the two values val1 and val2 |
Math.pow(base, exp) | Returns the value of base raised to the exp power |
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 |