import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Lê o número inteiro N
        int N = scanner.nextInt();
        Stack<Integer> stack = new Stack<>();

        // Lê N números inteiros e os coloca na pilha
        for (int i = 0; i < N; i++) {
            int num = scanner.nextInt();
            stack.push(num);
        }

        // Imprime os números na ordem inversa
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }

        scanner.close();
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: