0

13.2 Practice PRO Getting Things Done! (JAVA)

I have to output three task, but I don't how. Can someone tell me? "" 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"); } } }

15th Jun 2021, 7:14 PM
Vitali
Vitali - avatar
4 Respuestas
0
you must write only one generic solution wich handle all the "task" (test cases): your code will be executed once for each test case (3 test cases = code running 3 times)
15th Jun 2021, 7:24 PM
visph
visph - avatar
0
What are the 3 tasks there..? You are not adding anything to file. So it does not output anything... While loop doing nothing. I think you need to add count value to file in loop.. can you add description? non-pro not able see problem description..
15th Jun 2021, 8:17 PM
Jayakrishna 🇮🇳
0
for me the code below worked, but it doesn't print it on a new line and i dont know why. Maybe you guys can help me. But the lection is solved anyway, wether the words are on a new line each or not. //Your code goes here String t = input.nextLine(); f.format(t, "%s", "\n");
16th Oct 2021, 11:42 AM
Maximilian Heinrich
Maximilian Heinrich - avatar
0
I am having the same problem. can't write to file
12th Feb 2022, 5:20 PM
sebastien lalloz
sebastien lalloz - avatar