FearxBlaze05 FearxBlaze05
  • 24-11-2020
  • Computers and Technology
contestada

Populate a stack with ten random integers and empty it by showing that the order of the elements is reversed, from last to first.

CODE IN JAVA.

Thanks a Lot!

Respuesta :

tonb
tonb tonb
  • 24-11-2020

Answer:

class Main {  

 public static void main(String args[]) {

   Deque<Integer> stack = new ArrayDeque<Integer>();

   Random rand = new Random();

   for(int i=0; i<10; i++) {

       int n = rand.nextInt(100);

       System.out.printf("%02d ", n);

       stack.push(n);

   }

   

   System.out.println();

   

   while(stack.size() > 0) {

       System.out.printf("%02d ", stack.removeFirst());

   }

 }

}

Explanation:

example output:

31 18 11 42 24 44 84 51 03 17  

17 03 51 84 44 24 42 11 18 31

Answer Link

Otras preguntas

To be a school nurse requires only: A.an associate's degree. B.a license. C.a Ph.D. D.a high school diploma.
How many atoms of each type of element does this represent ?
what is the reciprocal of 3 and 1/5
how do you make babies
1. Select all irrational numbers. Square root of 10 Square root of 27 Square root of 49 Sq. Rt 64 Sq. Rt 99 2. Select all irrational numbers. 14√ 24√ 3
After escaping from exile, napoleon gathered volunteers from the french countryside and siezed power from who
What is the best first step in solving the equation 3 + = 5? Subtract 3 from both sides. Find the cube of . Cube both sides of the equation. Subtract 5 from b
Why did the existing inspection system fail to guard the safety of meat for human consumption?
which issues are barriers to good nutrition?
2x+5 is greater than 50 Please help im on the phone with my teacher