------------------------------------------------------------------------------
MC logo
Java Int Stack Driver
[^] Names and Scope
------------------------------------------------------------------------------
[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]
[Java Class Scope] [Ada Int Stack Package] [Ada Int Stack Impl] [Ada Int Stack Driver] [Java Int Stack Class] [Java Int Stack Driver] [C++ Int Stack Class] [C++ Int Stack Impl] [C++ Int Stack Driver]
driver.java
/*
 * A simple client of the IntStack package.
 */

import java.util.Scanner;

class Driver {
    public static void main(String[] args)
    {
        // Two test stacks.
        IntStack s1 = new IntStack();
        IntStack s2 = new IntStack();

        // Input scanner.
        Scanner in = new Scanner(System.in);

        // Uh...  A counter.
        int cnt = 1;

        // Read in integers until -1, and push each on one stack, and each
        // times the input ordinal on the other.
        int intin;              // Integer read in.
        do {
            System.out.print("> ");
            intin = in.nextInt();
            if(intin != -1) {
                s1.push(intin);
                s2.push(cnt*intin);
                ++cnt;
            }
        } while(intin != -1);

        // Pop 'em and print 'em
        while(!s1.isEmpty()) {
            int inout1 = s1.pop();
            int inout2 = s2.pop();
            System.out.println(inout1 + " " + inout2);
        }
    }
}