Exception in thread "main" java.lang.NumberFormatException: For input string: "datafile.txt" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.parseInt(Integer.java:527) at postfixstack.Main.main(Main.java:27) Java Result: 1
the file contains
1 + 2 - 3
I'm creating two stacks 1: operands, and 2: operators, and then displaying it
line 27 in Main contains "oprand.push(Integer.parseInt(next));"
package postfixstack; import java.util.*; public class Main { public static void main(String[] args) { Stack<String> optor = new Stack(); Stack<Integer> oprand = new Stack(); Scanner in = new Scanner("datafile.txt"); while(in.hasNext()) { String next = in.next(); if(optor.isOperator(next)) optor.push(next); else { oprand.push(Integer.parseInt(next)); } } System.out.println("Operators"); optor.display(); System.out.println("Operands"); oprand.display(); } }