Skip to content

Instantly share code, notes, and snippets.

@SiddharthManthan
Created November 13, 2021 17:27
Show Gist options
  • Save SiddharthManthan/3c637dac57cc7e93986e53a8ecb4a75e to your computer and use it in GitHub Desktop.
Save SiddharthManthan/3c637dac57cc7e93986e53a8ecb4a75e to your computer and use it in GitHub Desktop.
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Siddharth
*/
public class SandBox {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(Paths.get("recipes.txt"));) {
String name;
int cookingTime;
ArrayList<String> ingredients=new ArrayList<>();
String ingredient;
while(scanner.hasNextLine()) {
name=scanner.nextLine();
System.out.println(name);
cookingTime=Integer.valueOf(scanner.nextLine());
System.out.println(cookingTime);
while(scanner.hasNextLine()) {
ingredient=scanner.nextLine();
if(ingredient.isEmpty()) {
break;
}
ingredients.add(ingredient);
}
System.out.println(ingredients);
}
} catch (Exception e) {
System.out.println("Exception: "+e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment