-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1.java
More file actions
51 lines (45 loc) · 1.34 KB
/
Day1.java
File metadata and controls
51 lines (45 loc) · 1.34 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
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Day1 {
public static void main(String[] args) {
BufferedReader reader;
List<Integer> values=new ArrayList<Integer>();
try {
reader = new BufferedReader(new FileReader("C:\\Users\\DELL\\Desktop\\sample.txt"));
String line = reader.readLine();
while (line != null) {
int x = 0;
while(true)
{
if(line !=null)
{
if(line.length()!=0)
{
x+= Integer.parseInt(line);
line = reader.readLine();
}
else
{
line = reader.readLine();
break;
}
}
}
values.add(x);
// System.out.println(line);
if(line.length()==0)
{
System.out.println("hi");
}
// read next line
}
System.out.println(values);
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}