I am trying to store a string into an integer array with the following code:
public LargeInteger(String s) {
for (int i = 0; i < s.length(); i++) {
intArray[i] = Integer.parseInt( s.charAt(i));
}
}
eclipse is giving me an error saying: the method parseInt(string) is not applicable for the arguments (char)
What am I doing wrong?
You need to parse the
char, or convert it to aString.If you’re trying to get one digit at a time, and you know your input is a digit, then the easiest way to convert a single digit to an
intis justIf you want to keep using
Integer.parseInt, then just do