So I wrote a method which takes a string and converts each letter into an int via for loop. Each time the loop executes, I made it print out each value and add the value to a int array. The letter values should be from 0 to 25 which is why I have the c - 97. The print statements print the right number for each letter however at the end I also have it print out the entire array and I get a weird thing that it's printing. I don't think I'm adding the value correctly to the array so what am I doing wrong?
public int[] stringToIntArray(String text){
int ascii;
char c;
int a;
int[] array = new int[text.length()];
for (int i=0; i<text.length(); i++){
c = text.charAt(i);
a = c - 97;
array[i] = (a);
if (i != array.length - 1){
System.out.print(a + ", ");
} else {
System.out.print(a + " ");
}
}
System.out.print(array);
return array;
}