编写以下方法,如果参数中给的list数组已经按照升序排序好了,则返回true。
import java.util.Scanner;
public class _719是否已排序 {
public static boolean isSorted(int[] list){
boolean is = true;
for (int i = 1 ; i < list.length;i++){
if (list[i]<list[i-1]){
is = false;
}
}
return is;
}
public static void main(String[] args) {
int size;
Scanner sc = new Scanner(System.in);
size=sc.nextInt();
int[] list = new int[size];
for(int i = 0; i < size; i++){
list[i] = sc.nextInt();
}
System.out.println(isSorted(list));
}
}