hey guys, I wrote a code for my java class project. it is about stacks. you can see my code below. I don know why but it gives
runtime error. please help me out.
import java.util.*; import java.io.*; public class Test { private static char[] stack=new char[100000]; private static int stackPoint=-1; public static void main(String[] args) throws Exception { System.out.println("Enter file name: "); BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); String file=in.readLine(); Scanner scan=new Scanner(new FileReader(file)); out:while (scan.hasNext()) { String stg=scan.nextLine(); for(int i=0; i<stg.length(); i++) { if(stg.charAt(i)=='{' || stg.charAt(i)=='(' || stg.charAt(i)=='[') { push(stg.charAt(i)); } else if(i!=stg.length()-1 && stg.charAt(i)=='/' && stg.charAt(i+1)=='*') { push('/'); i++; } else if(stg.charAt(i)=='}' || stg.charAt(i)==')' || stg.charAt(i)==']') { char c=pop(); if(c=='-') break out; if(stg.charAt(i)=='}' && c!='{' || stg.charAt(i)==')' && c!='(' || stg.charAt(i)==']' && c!='[') { push(c); break out; } } else if(i!=stg.length()-1 && stg.charAt(i)=='*' && stg.charAt(i+1)=='/') { char c=pop(); if(c=='-') break out; if(c!='/') { push(c); break out; } } } } if(stackPoint==-1) { System.out.println("YES"); } else System.out.println("NO"); }static void push(char c) { stackPoint++; stack[stackPoint]=c; } static char pop() { stackPoint--; if(stackPoint<=-2) return '-'; return stack[stackPoint+1]; } }