[code] import java.io.*; import java.util.*; class Predict{ public static void m
ID: 3609047 • Letter: #
Question
[code]
import java.io.*;
import java.util.*;
class Predict{
public static void main(String[] args)throws IOException{
String[]pol = new String[100];
Scanner in = new Scanner (newFileReader("input.txt"));
int i = 0;
String line = in.nextLine();
String str = " ";
while(!(line.equals("$$$"))){
str =in.next();//NoSuchElementException
pol[i] = str;
i++;
line = in.nextLine();
}
}//main
}//class
[/code]
----text file------
Pale choose chosen called move
predictive TEXT mobile
Phone Spell Message Note SaKe
$$$$
I am trying to read theabove first by reading a line and then breaking up the line intowords and save then in an array, but it is giving me str =in.next();//NoSuchElementException. Help needed.
Explanation / Answer
//Hope this will help you.. import java.io.*; import java.util.*; class Predict{ public static void main(String[] args)throws IOException{ String[]pol = new String[100]; Scanner in = new Scanner (new FileReader("input.txt")); int i = 0; // String line = in.nextLine(); String str = in.next(); while(!(str.equals("$$$$"))){ //check it , is it $$$$ or $$$ in last. pol[i] = str; i++; System.out.println(str); str = in.next(); } }//main }//class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.