APCSA cram notes.
General rule for traversing a string (going through each character):
for (int i = 0; i < string.length(); i++)
{
String character = string.substring(i, i + 1);
}Constructor: initializing an object
contructor overloading: Having the same constructor in the same class but with different parameters
method overloading: Having the same method in the same class but with different parameters.
Random interger generator
//generates a random integer from 1 to 10, exclusive:
int random = (int)(Math.random()*9) + 1
//generates a random integer from 1 to 10, inclusive:
int random2 = (int)(Math.random()*10)+1Generate a random int from [min, max]:
int randomNum = (int)(Math.random() * (max - min + 1)) + min;String methods
Finding an index of a certain value in a list:
String pp = "hello world";
int index = pp.indexOf("world");
System.out.print(index);
//output will be 6
//if the string cannot be found, it will return -1