justin day 2
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
class part1{
|
||||
public static void main(String[] args){
|
||||
File input = new File("Day 2/Justin/Java/input.txt");
|
||||
|
||||
try{
|
||||
// Get the file, and start to read it
|
||||
Scanner fileIn = new Scanner(input);
|
||||
|
||||
int depth = 0;
|
||||
int movement = 0;
|
||||
|
||||
do{
|
||||
String inputLine = fileIn.nextLine();
|
||||
System.out.println(inputLine);
|
||||
String[] operations = inputLine.split(" ");
|
||||
switch(operations[0]){
|
||||
case "forward":
|
||||
movement += Integer.parseInt(operations[1]);
|
||||
break;
|
||||
case "up":
|
||||
depth -= Integer.parseInt(operations[1]);
|
||||
break;
|
||||
case "down":
|
||||
depth += Integer.parseInt(operations[1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while(fileIn.hasNextLine());
|
||||
|
||||
fileIn.close();
|
||||
|
||||
System.out.println(depth * movement);
|
||||
|
||||
} catch(FileNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user