Created
September 1, 2015 18:12
-
-
Save jweinst1/da6de79d3c48e5d18e9a to your computer and use it in GitHub Desktop.
Checks if an Int array is sorted in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| class Main { | |
| public static void main(String[] args) { | |
| System.out.println(issorted(lst)); | |
| } | |
| static int[] lst = {1, 0, 2, 3}; | |
| static boolean issorted(int[] x) { | |
| int size = x.length; | |
| for(int i=0; i<size-1; i++) { | |
| if (x[i] > x[i+1]) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment