Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in

Sequence

Is the array sorted?

Core exercise

Write estTrie(int[] tableau) that returns true if the array is sorted in ascending order (non-strictly: two equal values side by side are accepted). An empty or single-element array is sorted.

A workshop goes here: you write and run code in it. It requires JavaScript.

Starting code

Exercices.java

public class Exercices {

    public static void main(String[] args) {
        System.out.println(estTrie(new int[] { 1, 2, 3 }));
        System.out.println(estTrie(new int[] { 3, 1, 2 }));
    }

    public static boolean estTrie(int[] tableau) {
        // TODO
        return false;
    }
}

The core exercise is validated in the workshop, which requires JavaScript.

Hint 1

Compare each element with the next one: the loop therefore goes up to length - 1, not length.