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



Ask a Question

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. wow , really good java sample , and i suggest to s
View Tutorial          By: kiemtheng at 2011-08-31 13:31:32

2. great.....
View Tutorial          By: rashid at 2009-12-07 03:22:46

3. Hi!
this morning when i tried to logon a pr

View Tutorial          By: Lukas at 2013-03-03 13:35:42

4. It is simple and clear.. Thnx.
View Tutorial          By: kiru at 2010-04-06 01:48:04

5. The xml listed above will allow ANY domain to exec
View Tutorial          By: Mark McWhirter at 2012-10-09 05:58:14

6. It gives strange result when we use == as delimite
View Tutorial          By: Amit at 2010-05-07 05:03:41

7. nice... thanks for the explain, you safe my day...
View Tutorial          By: Joseph Louis at 2011-05-11 08:53:53

8. Hello,
I would like to know how will take p

View Tutorial          By: Jeff at 2011-02-02 23:05:17

9. It would be nice to add the line,


View Tutorial          By: Anonymous at 2009-08-30 07:59:10

10. Thanks for the useful tutorials abt strtus 1 vs St
View Tutorial          By: Sudharsan at 2011-12-03 11:54:58