I am doing this program and I keep getting "null" error at the end of output when I print as you see in the code. It does read file fine, but at the end, it adds so many null. Any guidance will be appreciated! Here 's what I tried so far.
public static void main(String[] args) throws Exception
{
Stack nifo=new Stack();
FileReader file = new FileReader("infix.dat");
try (BufferedReader br = new BufferedReader(file)) {
String [] words = new String[50];
String text="";
int ctrl = 0;
String Line =br.readLine();
while (Line!= null)
{
words[ctrl]= Line;
Line = br.readLine();
ctrl = ctrl + 1;
}//end of while loop
for (int i = 0; i < words.length; i++)
{
System.out.println(words[i]);
}
file.close();
} catch (IOException e) {
e.printStackTrace();
}//end of catch
}//end of main class
and my output is this below. As you see null is being printed at the end after I read my file.
5 * 6 + 4
3 - 2 +
( 3 * 4 - (2 + 5)) * 4 / 2
10 + 6 * 11 -(3 * 2 + 14) / 2
2 * (12 + (3 + 5 ) * 2
null
null
null
null
more nulls after that.
Thank you!