Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int N = Integer.parseInt(s.nextLine());
- //create array of booleans
- String[] answers = new String[N];
- //keep all answers in array
- for (int i = 0; i < N; i++) {
- answers[i] = String.valueOf(CheckSort());
- }
- //print answers elements
- for (String el : answers) {
- System.out.println(el);
- }
- }
- //create function that takes list input from console and returns boolean if list is sorted
- private static boolean CheckSort() {
- Scanner s = new Scanner(System.in);
- String StringInput = s.nextLine();
- //create array of Strings
- String[] ArrStrings = StringInput.split(",");
- //create sorted Array and keep clone of original Array, change both arrays to strings and compare them
- String[] sorted = ArrStrings.clone();
- Arrays.sort(sorted);
- String strSorted = String.join(",", sorted);
- String strArray = String.join(",", ArrStrings);
- return strArray.equals(strSorted);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement