CSE142 Midterm Cheat Sheet Math Method Description -------------------------------------- Math.abs(n) absolute value of n Math.max(x, y) maximum of x and y Math.min(x, y) minimum of x and y String Method Description ----------------------------------------------------------------------------- charAt(index) character at a specific index indexOf(text) index of a particular string (-1 if not found) length() number of characters in string substring(start, stop) characters from start (inclusive) to stop (exclusive) substring(start) characters from start to end of string toLowerCase() lowercase version of string toUpperCase() uppercase version of string equals(text) true if this string is the same as text 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(n) returns a random int between 0 and (n-1) inclusive Syntax Examples: for (int i = 1; i <= n; i++) { System.out.println("****"); } if (n < 0) { System.out.println("negative"); } if (n < 0) { System.out.println("negative"); } else { System.out.println("not negative"); } while (n < 200) { n = n * 2; }
Stuart Reges
Last modified: Mon Feb 6 10:37:52 PST 2012