Created
November 13, 2021 17:27
-
-
Save SiddharthManthan/3c637dac57cc7e93986e53a8ecb4a75e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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