Printing string array from another method?
im wanting to call that dump() method in our main, nonetheless it wont outprint that string array “wordList” like i want it that will, can any one give me personally any points I preserving getting errors, because connected with my “dump” method at the bottom.
————————————–
scan java.util.Scanner;
criminal court class MatchVerb
criminal court static useless main(String args) throws Exception
Scanner input = fresh Scanner(System.in);
// induce user to enter file
System.out.print(“Enter name of report of verbs:”);
Stringed fName = enter.nextLine();
Dictionary verbs = fresh Dictionary(fName);
// your own code should go here…
verbs.dump();
school Dictionary
criminal court String wordList;
ultimate int MAXWORDS = 10000;
Dictionary(String fileName) throws Exception
// learn a report called fileName
// retailer each collection from document into wordList
// your own code should go here…
Stringed wordList = fresh String MAXWORDS;
espresso.io.Report file = fresh java.io.File(fileName);
Scanner input = fresh Scanner(file);
int post = 0;
even though (input.hasNext())
Stringed word = enter.next();
wordListi = term;
i++;
useless dump()
// art print all elements of wordList
// your own code should go here…
for(int x=0; x<wordList.time-span; x++)
System.out.print(wordListx);
Your dump() approach IS component to the Dictionary course.All though others seem to obtain missed the on the while report.
But you have a method-local distinction of wordList in the constructor that may be overriding your class-wide definition:
Dictionary(String fileName) throws Exception
// learn a report called fileName
// retailer each collection from document into wordList
// your own code should go here…
Stringed wordList = fresh String MAXWORDS; <==============
espresso.io.Report file = fresh java.io.File(fileName);
Get rid of the Stringed part, that way:
wordList = fresh String MAXWORDS;
and also the empty list problem in dump() should go away.
Expect that helps.
It seems if you ask me that your current dump method is not a compenent of your Dictionary category Try set dump into your Dictionary training.
school Dictionary
criminal court String wordList;
ultimate int MAXWORDS = 10000;
Dictionary(String fileName) throws Exception
// learn a report called fileName
// retailer each collection from document into wordList
// your own code should go here…
Stringed wordList = fresh String MAXWORDS;
espresso.io.Report file = fresh java.io.File(fileName);
Scanner input = fresh Scanner(file);
int post = 0;
even though (input.hasNext())
Stringed word = enter.next();
wordListi = term;
i++;
useless dump()
// art print all elements of wordList
// your own code should go here…
for(int x=0; x<wordList.time-span; x++)
System.out.print(wordListx);
Instead of creating a method referred to as dump, I propose actually creating a toString method in the Dictionary class.
Alter:MT also posted a wonderfully acceptable option.You should however become familiar with toString in order to do coffee.
its not located within the verbs course, just try dump();
Leave a Reply
You must be logged in to post a comment.