Advertisement
Jhonny_V

Untitled

Oct 1st, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner s = new Scanner(System.in);
  7.         int N = Integer.parseInt(s.nextLine());
  8.         //create array of booleans
  9.         String[] answers = new String[N];
  10.         //keep all answers in array
  11.         for (int i = 0; i < N; i++) {
  12.             Scanner sd = new Scanner(System.in);
  13.             String StringInput = sd.nextLine();
  14.             //create array of Strings
  15.             String[] ArrStrings = StringInput.split(",");
  16.             //create sorted Array and keep clone of original Array, change both arrays to strings and compare them
  17.             String a = "true";
  18.             for (int j = 0; j < ArrStrings.length - 1; j++) {
  19.                 int num1 = Integer.parseInt(ArrStrings[j]);
  20.                 int num2 = Integer.parseInt(ArrStrings[j + 1]);
  21.  
  22.                 if (num1 > num2) {
  23.                     a = "false";
  24.                     break;
  25.                 }
  26.  
  27.             }
  28.             answers[i] = a;
  29.         }
  30.         //print answers elements
  31.         for (int ij = 0; ij < answers.length; ij++) {
  32.             System.out.println(answers[ij]);
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement