It only appears when I enter 10 or more numbers that are 3's and 7's. It is coming from this method below, I tested it without this method. Here is the code
Scanner input = new Scanner(System.in);
System.out.print("Enter a positive integer...");
int num = input.nextInt();
// Outputs
System.out.println("Number of digits in number is " + numberDigits(num));
System.out.println("Number begins with " + firstNum(num));
System.out.println("Number ends with " + lastNum(num));
System.out.println("Does number begin with 7? " + beginWith(num, 7));
System.out.println("Does number begin with 3? " + beginWith(num, 3));
System.out.println("Does number contain a 7? " + contains(num, 7));
System.out.println("Does number contain a 3? " + contains(num, 3));
System.out.println("Is the number divisible by 13? " + divTest(num, 13));
System.out.println("Is the number divisible by 77? " + divTest(num, 77));
System.out.println("How many times does 7 appear in the number? " + digitAppearances(num, 7));
System.out.println("How many times does 3 appear in the number? " + digitAppearances(num, 3));
public static int digitAppearances(int num, int x) {
// Check if num is 0
if (num <= 0 ) {
return 0;
}
// Count number of times x appears
else if (num % 10 == x) {
return 1 + digitAppearances(num / 10, x);
}
else {
return digitAppearances(num / 10, x);
}
}
InputMismatchExceptionInputMismatchExceptionis thrown by aScanner, but I don't see one here. Please post the code that actually throws that exception.