-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompact.java
More file actions
47 lines (44 loc) · 1.17 KB
/
Compact.java
File metadata and controls
47 lines (44 loc) · 1.17 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
/**
* Write a description of class Compact here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.util.Scanner;
import java.io.*;
public class Compact
{
private String fileLocation;
/**
* Constructor for objects of class Compact
*/
public Compact()
{
fileLocation = "D:\\Comp Sci\\Comp Sci\\compact.txt";
Scanner in;
int[] numbers = new int[20];
try{
in = new Scanner(new File(fileLocation));
int count = 0;
while(in.hasNextInt()){
int num = in.nextInt();
if(num != 0){
numbers[count] = num;
count++;
}
}
}
catch(IOException i){
System.out.println("Error: " + i.getMessage());
}
for(int i = 0; i < numbers.length; i++){
if(numbers[i] != 0){
System.out.println(numbers[i]);
}
}
// System.out.println(numbers[0]);
// System.out.println(numbers[1]);
// System.out.println(numbers[2]);
}
}