error: illegal start of type

后端 未结 3 1926
渐次进展
渐次进展 2021-01-07 15:48

why this little piece of code is giving illegal start of type error in line 6 and 10(for loops).... i can\'t find any unmatched braces...

class StackDemo{
           


        
3条回答
  •  庸人自扰
    2021-01-07 16:05

    You can't use for loop in class level. Put them inside a method or a block

    Also java.util.Stack in Java don't have such constructor.

    It should be

    Stack s = new Stack()
    

    Another issue

    s.push(char('A'+i))// you will get Unexpected Token error here
    

    Just change it to

    s.push('A'+i);
    

提交回复
热议问题