posted Sep 24, 2018, 6:18 AM by Konstantinovich Samuel   [ updated Sep 24, 2018, 7:43 AM ]
Exam Friday

Classwork / HW


When you read the java documentation, pay attention to when they throw exceptions (runtime errors), and when they return special values. 

Here is the AP subset of Java you need to know:

Strings are here:

1 charAt(int)
2 length()
3 equals(String)
4 compareTo(String)
5 indexOf(String)
6 substring(int,int)
7 substring(int)

CompareTo: See if the strings are the same, if not then look at the first different charcter of the two strings.
"Hello".compareTo("Hello") ->  0 since the strings are the same.
"Hello".compareTo("Apple") ->  a positive value  since 'H' > 'A'
"Hello".compareTo("hello") ->  a negative value  since 'H' < 'h'
"Hello".compareTo("apple") ->  a negative value  since 'H' < 'a'
"xxx".compareTo("xxa") ->  a positive value  since 'x' > 'a'
"xx".compareTo("xxa") ->  a negative value  since given all characters are the same, but one is longer, the shorter string is considered smaller.

Goal: For Loops!

int x = 0; //initialize

while (x<10){ //check


x++;        //increment


equivalent to this is:

for( int x = 0; x<10; x++){



Basic syntax for a "for" loop:

for(initialize; check; increment){



However, when you declare a variable inside of a "for" loop, it will not be defined outside of the function.

 - If you define the variable, x, outside of the "for" loop, you will be able to use it both in the "for" loop and outside of it.

In a "while" loop, there is much flexibility inside of the body, where the parts such as the increment and body can be scrambled.

On the other hand, in "for" loops, the format is much stricter.