this is the problem link
import java.io.;
import java.util.;
/* Name of the class has to be “Main” only if the class is public.
By : SSD
*/
class Codechef {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
private static int precedence(char ch)
{
if (ch=='+'|| ch=='-')
{
return 1;
}
else if (ch=='*' || ch =='/')
{
return 2;
}
else if (ch=='^')
{
return 3;
}
else
{
return -1;
}
}
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
StringBuilder res = new StringBuilder();
int t = sc.nextInt();
while (t-- > 0) {
int n=sc.nextInt();
String infix = sc.next();
StringBuilder ans = new StringBuilder();
Stack <Character> st = new Stack<>();
for (char ch : infix.toCharArray())
{
if (Character.isLetter(ch))
{
ans.append(ch);
}
else if (ch=='(')
{
st.push(ch);
}
else if (ch==')')
{
while(st.peek()!='(')
{
ans.append(st.pop());
}
st.pop();
}
else
{
int p=precedence(ch);
while (!st.isEmpty() && p<=precedence(st.peek()))
{
ans.append(st.pop());
}
st.push(ch);
}
}
while (!st.isEmpty())
{
ans.append(st.pop());
}
res.append(ans +"\n");
}
System.out.println(res);
}
}
here is my code in java, it is giving NZEC error with description
Exception in thread “main” java.lang.NullPointerException
at java.util.StringTokenizer.(StringTokenizer.java:199)
at java.util.StringTokenizer.(StringTokenizer.java:236)
at Codechef$FastReader.next(Main.java:26)
at Codechef$FastReader.nextInt(Main.java:35)
at Codechef.main(Main.java:78)
kindly help me to solve this.