My code for infix to postfix transformation problem is as follows
package CodeChef;
import java.util.Scanner;
import java.util.Stack;
/**
* Created by Aniket on 2/23/14.
*/
public class PostFixConverter {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int noOfTestCases = Integer.parseInt(scanner.nextLine());
for(int i=0;i<noOfTestCases;i++){
printPostFix(scanner.nextLine());
}
}
public static void printPostFix(String str){
Stack<Character> stack = new Stack<>();
for(int i=0;i<str.length();i++){
char c = str.charAt(i);
if(Character.isLetter(c)){
System.out.print(c);
}
else if(c == '('){
continue;
}
else if(c == ')'){
System.out.print(stack.pop());
}
else{
stack.push(c);
}
}
System.out.println();
}
}
Compiles and runs fine on my machine. But on code chef it give me following compile time error
Main.java:22: illegal start of type Stack stack = new Stack<>(); ^ 1 error
Can someone point out what exactly the problem is?