fork download
  1. import java.util.Stack;
  2.  
  3. class VehicleInspection {
  4.  
  5. public static void main(String[] args) {
  6. // Create a Stack to hold inspections
  7. Stack<Integer> inspectionStack = new Stack<>();
  8.  
  9. // Pushing three inspections to the stack
  10. inspectionStack.push(0); // Initial inspection (station 1)
  11. inspectionStack.push(1); // First testing station
  12. inspectionStack.push(2); // Second testing station
  13.  
  14. // Pop values as the vehicle passes through each testing station
  15. System.out.println("Inspection sequence starting...");
  16.  
  17. // First inspection (Station 1)
  18. int inspection1 = inspectionStack.pop();
  19. System.out.println("Popped at First Testing Station: " + inspection1);
  20. System.out.println("Stack after First Testing Station: " + inspectionStack);
  21.  
  22. // Second inspection (Station 2)
  23. int inspection2 = inspectionStack.pop();
  24. System.out.println("Popped at Second Testing Station: " + inspection2);
  25. System.out.println("Stack after Second Testing Station: " + inspectionStack);
  26.  
  27. // Third inspection (Station 3)
  28. int inspection3 = inspectionStack.pop();
  29. System.out.println("Popped at Third Testing Station: " + inspection3);
  30. System.out.println("Stack after Third Testing Station: " + inspectionStack);
  31. }
  32. }
  33.  
Success #stdin #stdout 0.11s 57540KB
stdin
Standard input is empty
stdout
Inspection sequence starting...
Popped at First Testing Station: 2
Stack after First Testing Station: [0, 1]
Popped at Second Testing Station: 1
Stack after Second Testing Station: [0]
Popped at Third Testing Station: 0
Stack after Third Testing Station: []