I\'m trying to convert an array of characters into integers, so I can get the ascii code, but the code I have doesn\'t seem to be working.
import javax.swing.*;
You don't need to explicitly cast it. You may simply assign it to int. Refer 5.1.2. Widening Primitive Conversion
Example:
char[] charArray = "test".toCharArray();
for (int count = 0; count < charArray.length; count++) {
int digit = charArray[count];
System.out.println(digit);
}
output:
116
101
115
116
digit
is an int
type primitive variable can't be treated as an array
digit[count])
just use
digit
Try it this way...
char[] charArray = phrase.toCharArray();
int[] intArray = new int[charArray.length];
int i=0;
for (char c : charArray){
intArray[i] = c;
i++;
}