How to check if an array is strictly increasing in Java

1 Answer

0 votes
class Program {
    private static boolean strictly_increasing(int[] arr) {
        int size = arr.length;
        
    	for (int i = 0; i < size - 1; i++) {
    		if (!(arr[i] < arr[i + 1])) {
    			return false;
    		}
    	}
    
    	return true;
    }
    
    public static void main(String[] args) {
        int[] arr = {1, 3, 4, 6, 8, 9, 11, 17, 18, 37};
        
        System.out.print(strictly_increasing(arr) ? "true" : "false");
    }
}




/*
run:
 
true
 
*/

 



answered Feb 26, 2024 by avibootz

Related questions

1 answer 112 views
1 answer 119 views
1 answer 155 views
1 answer 188 views
...