Reputation: 348
Ok so when I use this code instead of a 9999 I get 57 for each 9? Pretty confused new to Java any help would be appreciated!!
public int[] getNumber(){
String newNum;
Scanner input = new Scanner( System.in );
System.out.println( "Please enter four digits" );
newNum = input.nextLine();
char[] list = newNum.toCharArray();
int[] numArray = new int[newNum.length()];
for (int i = 0; i < newNum.length(); i++){
numArray[i] = list[i];
}
return numArray;
}
Upvotes: 0
Views: 43
Reputation: 691725
Yes. 57 is the integer value of the char '9'. So it's expected. If you want the numeric value of the char, use
numArray[i] = list[i] - '0';
Upvotes: 1