You will be provided a cheat sheet with the information below on your midterm. If you are interested in the actual format of the document, check out this year's version.
if (test) {
statement(s);
}
if (test) {
statement(s);
} else {
statement(s);
}
if (test) {
statement(s);
} else if (test) {
statement(s);
} else {
statement(s);
}
for (initialization; test; update) {
statement(s);
}
while (condition) {
statement(s);
}
public static void name(parameters) {
statement(s);
}
public static type name(parameters) {
statement(s);
...
return expression;
}
Scanner console = new Scanner(System.in);
Random r = new Random();
Math Method |
Description |
Math.abs(value) |
absolute value |
Math.min(v1, v2) |
smaller of two values |
Math.max(v1, v2) |
larger of two values |
Math.round(value) |
nearest whole number |
Math.pow(b, e) |
base to the exponent power |
Scanner Method |
Description |
nextInt() |
reads/returns input as int |
nextDouble() |
reads/returns input as double |
next() |
reads/returns input as String |
Random Method |
Description |
nextInt(max) |
random integer from 0 to max-1 |
String Method |
Description |
contains(str) |
true if this string contains the other's characters inside it |
endsWith(str), startsWith(str) |
true if this string starts/ends with the other's characters |
equals(str) |
true if this string is the same as str |
equalsIgnoreCase(str) |
true if this string is the same as str, ignoring capitalization |
indexOf(str) |
index in this string where given string begins (-1 if not found) |
length() |
number of characters in this string |
substring(i, j) |
characters in this string from index i (inclusive) to j (exclusive) |
substring(i) |
characters in this string from index i (inclusive) to end |
toLowerCase() , toUpperCase() |
a new string with all lowercase or uppercase letters |
charAt(i) |
returns char at index i |
Operator |
Description |
< |
less than |
<= |
less than or equal |
> |
greater than |
>= |
greater than or equal |
== |
equal to |
!= |
not equal to |
&& |
logical and |
` |
|
! |
logical not |