-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh07Q19.java
More file actions
executable file
·38 lines (36 loc) · 1.26 KB
/
Ch07Q19.java
File metadata and controls
executable file
·38 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* */ package ch07;
/* */
/* */ import java.util.Arrays;
/* */ import java.util.Scanner;
/* */
/* */ public class Ch07Q19 {
/* */ public static void main(String[] args) {
/* 8 */ Scanner scanner = new Scanner(System.in);
/* 9 */ System.out.print("Enter list: ");
/* 10 */ int totalNumbers = scanner.nextInt();
/* 11 */ int[] orig = new int[totalNumbers];
/* 12 */ for (int i = 0; i < totalNumbers; i++) {
/* 13 */ orig[i] = scanner.nextInt();
/* */ }
/* 15 */ int[] sorted = new int[totalNumbers];
/* 16 */ System.arraycopy(orig, 0, sorted, 0, orig.length);
/* 17 */ Arrays.sort(sorted);
/* 18 */ boolean isSorted = true;
/* 19 */ for (int j = 0; j < sorted.length; j++) {
/* 20 */ if (orig[j] != sorted[j]) {
/* 21 */ isSorted = false;
/* */ break;
/* */ }
/* */ }
/* 25 */ if (isSorted) {
/* 26 */ System.out.println("The list is already sorted");
/* */ } else {
/* */
/* 29 */ System.out.println("The list is not sorted");
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch07/Ch07Q19.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/