Task: if array is not sorted, throw IllegalStateException. Else return true.
An integer n (size of array)
Then n integers (array elements)
If array is sorted (non-decreasing) → return true
If not sorted → throw IllegalStateException
• n ≥ 0
• Sorted means: a[i] >= a[i-1] for all valid i
We check every adjacent pair.
If any element is smaller than the previous one,
array is not sorted.
1.Read n and the array.
2.Loop from i = 1 to n-1:
• If a[i] < a[i-1]:
• Throw new IllegalStateException("Array not sorted").
3.If loop completes without exception:
• Return true.