Becareful to use .equal() with str.substring(i, i +1)