P
P
Pavel Rekun2014-10-18 15:52:40
Java
Pavel Rekun, 2014-10-18 15:52:40

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

1 answer(s)
V
Vladislav, 2014-10-18
@Div100

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 question

Ask a Question

731 491 924 answers to any question