error: illegal start of type

后端 未结 3 1797
渐次进展
渐次进展 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:03

    You can't just write code in a class, you need a method for that:

    class StackDemo{
        static final int size = 10;
        static Stack s = new Stack(size);
    
        public static void main(String[] args) {
            //Push charecters into the stack
            for(int i=0; i

    The method main is the entry point for a Java application. The JVM will call that method on program startup. Please notice that I've added the code word static to your variables, so they could be directly used in the static method main.

提交回复
热议问题