-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCreator.java
More file actions
25 lines (23 loc) · 971 Bytes
/
ImageCreator.java
File metadata and controls
25 lines (23 loc) · 971 Bytes
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
import java.io.*;
/* This program uses no arrays. It is put here because it is useful
for use with some of the other programs of this section */
//This program creates a 64 by 64 image as a text file
//Uses output redirection to send the output to a file
public class ImageCreator {
public static void main(String[] args) {
try (FileWriter writer = new FileWriter("image.txt")) {
/* The image starts out with 8 rows of 64 zeros. Next, the image has 8 rows
of 64 eights. Next, the image has 8 rows of 64 sixteens, and so on */
for (int i = 0 ; i < 8 ; i++) {
for (int j = 0 ; j < 512 ; j++) {
writer.write(String.valueOf(i * 8));
//writes one value per line, without spaces or commas
writer.write('\n');
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}