-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay2Dive.java
More file actions
39 lines (37 loc) · 1.1 KB
/
Copy pathDay2Dive.java
File metadata and controls
39 lines (37 loc) · 1.1 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
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner;
class Day2Dive {
public static void main(String args[]){
int horizontal = 0;
int depth = 0;
int aim = 0;
try{
File data = new File("Day2DiveData.txt");
Scanner sc = new Scanner(data);
while(sc.hasNext()){
String command = sc.next();
int value = sc.nextInt();
if (command.equals("forward")){
horizontal += value;
depth += aim*value;
}
else if(command.equals("down")){
aim += value;
}
else if(command.equals("up")){
aim -= value;
}
//System.out.println("Command is: " + command + " for a value of: " + value);
}
sc.close();
}
catch(FileNotFoundException e){
System.out.println("Ye fucked up");
e.printStackTrace();
}
System.out.println("Horizontal is: " + horizontal + " Depth is: " + depth);
int product = horizontal * depth;
System.out.println("product of both equals: " + product);
}
}