1166: 判断升序

来源:互联网 发布:plc称重模块怎样编程 编辑:程序博客网 时间:2024/06/07 00:47

题目

Description

实现public static boolean isSorted(int[] table)

判断整数数组元素是否已经按升序排序。

Input

一列数,需要判断的数组元素。

Output

如果已经排序输出YES

如果没有排序输出NO

Sample Input

1
2
3
4
5
6
Sample Output

YES


代码块

import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cn = new Scanner(System.in);        int[] n = new int[10001];        int i =0;        while(cn.hasNext()){            n[i] =cn.nextInt();            i++;        }        if(isSorted(n,i))//进行判断输出            System.out.println("YES");        else System.out.println("NO");    }    private static boolean isSorted(int[] n,int i) {        for(int j =0 ;j<i-1;j++){            if(n[j]>n[j+1]) return false;        }        return true;    }}
原创粉丝点击