Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Advent-of-Code2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mdejournett2
Advent-of-Code2022
Merge requests
!1
Done in 21 lines of code
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Done in 21 lines of code
mdejournett2-main-patch-14249
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
mdejournett2
requested to merge
mdejournett2-main-patch-14249
into
main
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
53965259
1 commit,
2 years ago
1 file
+
18
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Day1/day1code
+
18
−
12
Options
import java.nio.file.*;;
public class day1code{
public static void main(String[] args){
String[] items = "1000 2000 3000 \n4000 5000 6000 \n7000 8000 9000 \n10000".split(" \n");
int maxCalorieCount = 0;
for (int counter=0;counter<items.length;counter++){
int currentCalorieCount =0 ;
String[] eachItem = items[counter].split(" ");
for(int innerCounter =0;innerCounter<eachItem.length;innerCounter++){
currentCalorieCount = currentCalorieCount+Integer.parseInt(eachItem[innerCounter]);
}
if (currentCalorieCount>maxCalorieCount)maxCalorieCount=currentCalorieCount;
public static String readFileAsString(String fileName)throws Exception{
String data = "";
data = new String(Files.readAllBytes(Paths.get(fileName)));
return data;
}
System.out.println(maxCalorieCount);
}
public static void main(String[] args) throws Exception{
String[] items = readFileAsString("C:\\Users\\micha\\Desktop\\Day 1\\inputData.txt").split("\n");
String [] newItems=String.join(",", items).split(",");
int maxCalorieCount = 0;
int currentCalorieCount=0;
for(int innerCounter =0;innerCounter<newItems.length;innerCounter++){
if(newItems[innerCounter].replaceAll("[^\\d.]", "")==""){
currentCalorieCount=0;
}else currentCalorieCount = currentCalorieCount+Integer.parseInt(newItems[innerCounter].replaceAll("[^\\d.]", ""));
if (currentCalorieCount>maxCalorieCount)maxCalorieCount=currentCalorieCount;
}
System.out.println(maxCalorieCount);
}
}
Loading