// Program to test solutions to problem #8 on the cse142 midterm, winter 2012. // Fill in your solution to increasingDigits, then compile and run the program. import java.util.*; public class Test8 { public static boolean increasingDigits(int n) { // fill in your solution here // you can also rename the parameter above } // this is the sample solution public static boolean increasingDigits2(int n) { int prev = n % 10; n = n / 10; while (n > 0) { int digit = n % 10; if (digit >= prev) { return false; } n = n / 10; prev = digit; } return true; } public static void main(String[] args) { // test 0 through 999,999, reporting up to 25 errors int count = 0; int n = 0; while (n <= 999999 && count < 25) { if (!test(n)) { count++; } n++; } if (count == 0) { System.out.println("all tests PASS"); } } public static boolean test(int n) { boolean ok = test2(n); if (!ok) { System.out.println("FAILS for n = " + n + " (should be " + increasingDigits2(n) + ")"); } return ok; } public static boolean test2(int n) { boolean test1; try { test1 = increasingDigits(n); } catch (RuntimeException e) { return false; } boolean test2 = increasingDigits2(n); return (test1 == test2); } }