0

writing files issues.

I have to output three task, but I don't know how. Can someone please help me? this is the puzzle: "" You want to plan your day and create your to do list. Complete the program to take the names of 3 tasks as input and write them down in the file "tasks.txt", each on a new line. Then use the readFile() method to output the tasks. Sample Code Workout Report Pool Sample Output Workout Report Pool "" import java.io.File; import java.util.Scanner; import java.util.Formatter; public class Main { public static void main(String[ ] args) { Scanner input = new Scanner(System.in); try { Formatter f = new Formatter("tasks.txt"); int count = 0; while(count < 3) { //your code goes here count++; } f.close(); } catch (Exception e) { System.out.println("Error"); } readFile(); } public static void readFile() { try { File x = new File("tasks.txt"); Scanner sc = new Scanner(x); while(sc.hasNext()) { System.out.println(sc.next()); } sc.close(); } catch (Exception e) { System.out.println("Error"); } } } My question is where do I get the info to populate my list. Scanner?

12th Feb 2022, 5:43 PM
sebastien lalloz
sebastien lalloz - avatar
2 odpowiedzi
0
you will get three inputs from Scanner loop.
12th Feb 2022, 6:21 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
From Scanner 'input'. Read input in while loop and add into file by Farmatter object. Job done.
12th Feb 2022, 8:20 PM
Jayakrishna 🇮🇳