-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh12Q15.java
More file actions
executable file
·57 lines (55 loc) · 1.78 KB
/
Ch12Q15.java
File metadata and controls
executable file
·57 lines (55 loc) · 1.78 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* */ package ch12_io;
/* */ import java.io.File;
/* */ import java.io.IOException;
/* */ import java.io.PrintWriter;
/* */ import java.util.Arrays;
/* */ import java.util.Random;
/* */ import java.util.Scanner;
/* */
/* */ public class Ch12Q15 {
/* */ public static void main(String[] args) {
/* 11 */ File f = new File("Exercise12_15.txt");
/* 12 */ if (f.exists()) {
/* 13 */ System.out.println("File already exists.");
/* 14 */ System.exit(1);
/* */ }
/* */
/* 17 */ try (PrintWriter output = new PrintWriter(f)) {
/* */
/* 19 */ Random r = new Random();
/* */
/* 21 */ for (int i = 0; i < 100; i++) {
/* 22 */ int data = r.nextInt() % 1000;
/* 23 */ output.print(data);
/* 24 */ output.print(' ');
/* */ }
/* 26 */ } catch (IOException ioe) {
/* 27 */ ioe.printStackTrace();
/* */ }
/* */
/* 30 */ int[] d = new int[100];
/* */
/* 32 */ try (Scanner input = new Scanner(f)) {
/* */ int i;
/* 34 */ for (i = 0; i < d.length; i++) {
/* 35 */ d[i] = input.nextInt();
/* */ }
/* 37 */ for (i = 0; i < d.length; i++) {
/* 38 */ System.out.print(d[i] + " ");
/* */ }
/* 40 */ System.out.println();
/* 41 */ Arrays.sort(d);
/* 42 */ for (i = 0; i < d.length; i++) {
/* 43 */ System.out.print(d[i] + " ");
/* */ }
/* 45 */ System.out.println();
/* */ }
/* 47 */ catch (IOException ioe) {
/* 48 */ ioe.printStackTrace();
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch12_io/Ch12Q15.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/