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{
final int size = 10;
Stack s = new Stack(size);
//Push charecters into the stack
for(int i=0; i<size; i++){
s.push((char)'A'+i);
}
//pop the stack untill its empty
for(int i=0; i<size; i++){
System.out.println("Pooped element "+i+" is "+ s.pop());
}
}
I have the class Stack implemented,
You can't just write code in a class, you need a method for that:
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 wordstatic
to your variables, so they could be directly used in the static methodmain
.You cannot use for loop inside a class body, you need to put them in some kind of method.
You can't use
for
loop in class level. Put them inside amethod
or ablock
Also
java.util.Stack
inJava
don't have such constructor.It should be
Another issue
Just change it to