Aleks_Tor

Is a List Sorted?[first one]

May 21st, 2021
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     static public boolean isSorted(int[] array) {
  6.         boolean sorted = false;
  7.         for (int i = 0; i < array.length - 1; i++) {
  8.             if (array[i] <= array[i + 1])
  9.                 sorted = true;
  10.             else {
  11.                 sorted = false;
  12.             }
  13.         }
  14.         return sorted;
  15.     }
  16.  
  17.     public static void main(String[] args) {
  18.         Scanner scanner = new Scanner(System.in);
  19.         int times = Integer.parseInt(scanner.nextLine());
  20.  
  21.         for (int i = 0; i < times; i++) {
  22.             String[] inputs = scanner.nextLine().split(",");
  23.             int[] conv = new int[inputs.length];
  24.             for (int j = 0; j < inputs.length; j++) {
  25.                 conv[j] = Integer.parseInt(inputs[j]);
  26.             }
  27.             System.out.println(isSorted(conv));
  28.         }
  29.     }
  30. }
RAW Paste Data