Monday, June 29, 2015

my{} JAVA stacknumberpop app

Write a java program that permits a user to enter a maximum of 10 intergers ointo a stack object, then have your program sort the stack contents into increasing order, (A-z) thus if the contents of the stack initially 4521 into 1245


package javaapplication2;
import java.util.Stack;
/**
 *
 * @author Class
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
        {
                // Create a new, empty stack
                Stack mynum = new Stack();
                System.out.println ("normal order is : 1, 2, 3, 4,");
                // Let's add some items to it
                for (int i = 1; i <= 4; i++)
                {
                        mynum.push ( new Integer(i) );
                }

                // Last in first out means reverse order
                while ( !mynum.empty() )
                {
                        System.out.print ( mynum.pop() );
                        System.out.print ( ',' );
                }

                // empty
                System.out.println (" reverse order empty last first then to least");
        }

}

No comments:

Post a Comment