class Monotonic { public static boolean monotonic(int[] a) { int n = a.length, i; for (i = 0 ; i < n - 1 ; i++) if (a[i+1] < a[i]) break; if (i == n - 1) return(true); // increasing for (i = 0 ; i < n - 1 ; i++) if (a[i+1] > a[i]) return(false); return(true); // decreasing } public static void main(String[] args) { int[] a = {1, 2, 3, 4, 4, 5, 10}; int[] b = {19, 12, 8, 4, 4, 0, -10}; int[] c = {1, 2, 3, 4, 3, 5, 10}; if (monotonic(a)) System.out.println("a monotonic."); if (monotonic(b)) System.out.println("b monotonic."); if (monotonic(c)) System.out.println("c monotonic."); } }