Comment on Tutorial - Stack example in Java - push(), pop(), empty(), search() By Henry



Comment Added by : jack&jill

Comment Added at : 2011-07-26 06:40:32

Comment on Tutorial : Stack example in Java - push(), pop(), empty(), search() By Henry
import java.io.*;
import java.util.Stack;
public class Stacks {
public static void main(String args[])throws IOException {
DataInputStream k=new DataInputStream(System.in);
Stack r=new Stack();
for(int i=1; i<=3; i++) {
System.out.print(" ");
System.out.print("Enter a value to PUSH: ");
int x=Integer.parseInt(k.readLine());
r.push (new Integer(x) );
System.out.print("Stacked: "+r+"\n");

}System.out.println("STACK IS FULL!");
do {
for(int i=1; i<=3; i++) {
System.out.print(" "
);
System.out.print("Enter a value to POP: ");
int x=Integer.parseInt(k.readLine());
r.pop();
System.out.print("Stacked: "+r+"\n");
}
}while(!r.empty());
System.out.println("STACK IS EMPTY!");
}
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. i want to know how to connect to a remote mysql da
View Tutorial          By: lixiang at 2013-04-23 04:32:58

2. I want de total main prg to send and receive... se
View Tutorial          By: sharu at 2011-09-12 16:49:24

3. The code is running successfully.........but , I m
View Tutorial          By: Harshita at 2013-03-26 19:25:58

4. copy of h.sheld
View Tutorial          By: vivek at 2011-08-31 13:12:36

5. Thank you very much sir.
One can simply exe

View Tutorial          By: rudhin at 2013-05-10 12:32:57

6. I want to store the Data in Vector or the LinkedLi
View Tutorial          By: Sobia at 2013-01-17 11:24:59

7. can u pls tell me how to retrive data from databas
View Tutorial          By: yogesg desai at 2010-05-27 08:26:24

8. nice work.......
View Tutorial          By: sukirti at 2011-05-06 16:30:19

9. It's so crazy to the adventures of J2ME side and w
View Tutorial          By: jaikarthik at 2009-01-18 23:42:42

10. Thanks for the introduction of j2me
View Tutorial          By: AKbar Ali at 2009-10-19 03:56:58