------------------------------------------------------------------------------
MC logo
Java Generic Driver
[^] Types and Type Systems
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Type Propagation] [Array Location Arithmetic] [Java Generic] [Java Generic Driver]
stktst.java
import java.io.*;
import java.util.*;

public class stktst {
    public static void main(String [] args)
    {
        // Make a stack of Integers.
        Stack<Integer> is = new Stack<>(30);

        System.out.print("Enter integers to -1:\n> ");
        BufferedReader bufferedReader = new BufferedReader
            (new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(bufferedReader.readLine().trim());
            while(n != -1) {
                is.push(n);
                System.out.print("> ");
                n = Integer.parseInt(bufferedReader.readLine().trim());
            }
        } catch(IOException e) {
        }

        while(!is.empty())
            System.out.print(is.pop() + " ");
        System.out.println();

        // Make a stack of strings.
        Stack<String> ss  = new Stack<>(50);

        System.out.print("Enter lines to blank:\n> ");

        try {
            String s = bufferedReader.readLine();
            while(!s.equals("")) {
                ss.push(s);
                System.out.print("> ");
                s = bufferedReader.readLine();
            }
        } catch(IOException e) {
        }
        System.out.println();
        while(!ss.empty())
            System.out.println(ss.pop() + " ");
    }
}