Reputation: 31
How do I rewrite this code to not have the Type Mismatch error on return Math.abs(i);
public static int[] countDigits(Scanner input) {
int[] count = new int[10];
int i = input.nextInt();
while (Math.abs(i) >= 10 ) {
i = i / 10;
}
return Math.abs(i);
This is the segment of code in particular that I need help with.It Reads integers from input, computing an array of counts for the occurrences of each leading digit (0-9).
Upvotes: 0
Views: 42
Reputation: 201537
Change your return type from int[]
to int
... because Math.abs returns one Integer. Not an array of Integers. Like this
public static int countDigits(Scanner input)
Upvotes: 1