Answer the question
In order to leave comments, you need to log in
How to use one variable to fill the stack?
Hello, I have a question, how in Java it is possible to fill the stack with one variable, but with different values. It means that one int variable gets different values under different conditions and all these values must be written to the stack. How to do this?
Answer the question
In order to leave comments, you need to log in
Not quite sure what you mean, but here are a couple of examples.
Stack<Integer> stack = new Stack<Integer>();
Integer value = 1;
stack.add(value);
value = 2;
stack.add(value);
//и т.д
Stack<Integer> stack = new Stack();
Integer value = 1;
for(;value<10;value++)
stack.add(value);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question