0

Cannot print File

Hey! I wrote this code for a simple vocab trainer. I'm new to Files, thus this is a rather intricate affair. :/ The problem is that the System.out.println does not work. It says: No suitable method found for println() import java.util.*; import java.io.*; import java.lang.*; public class Vocabs { private Formatter form; private Scanner sc; public void openFile() { try{ form = new Formatter("vocabs.txt"); sc = new Scanner(new File("vocabs.txt")); } catch(Exception e) { System.out.println("An error occured"); } } public void addVocab() { form.format("%s%s%s","one ","en ","sounds like and"); } public void closeFile() { form.close(); } public void readFile() { while(sc.hasNext()) { String LangA = sc.next(); String LangB = sc.next(); String Hint = sc.next(); System.out.println("%s%s%s%n", LangA, LangB, Hint); } } }

9th Feb 2019, 10:07 PM
Gino ^^
Gino ^^ - avatar
4 Respostas
+ 2
Try concatenating it instead. System.out.println(LangA + LangB + Hint);
9th Feb 2019, 10:19 PM
Jomari Pantorilla
Jomari Pantorilla - avatar
+ 1
I think you can use printf if you want to use format specifier like that last println call. String a ="So", b="loL", c="earn"; System.out.printf("%s%s%s\n", a, b, c); // output: "SoloLearn"
10th Feb 2019, 9:42 AM
Ipang
+ 1
What you use %n for, you meant \n maybe?
10th Feb 2019, 10:42 AM
Ipang
0
True but you would have to use %n then
10th Feb 2019, 10:22 AM
Gino ^^
Gino ^^ - avatar