Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote