Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created September 1, 2015 18:12
Show Gist options
  • Select an option

  • Save jweinst1/da6de79d3c48e5d18e9a to your computer and use it in GitHub Desktop.

Select an option

Save jweinst1/da6de79d3c48e5d18e9a to your computer and use it in GitHub Desktop.
Checks if an Int array is sorted in Java
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