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



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. Thanks alot that was quite helpful!
View Tutorial          By: Doaa at 2013-01-09 09:37:35

2. required the flag set loop stutruce .............
View Tutorial          By: savita at 2013-05-12 04:52:30

3. FINALLY! A place that gives complete examples (wi
View Tutorial          By: bminton at 2013-03-19 00:15:55

4. This tutorial is really fantastic.It helped me a l
View Tutorial          By: LakshmiNaryana Gorantla at 2010-04-19 23:35:45

5. how doeas peek work in a c++ program
View Tutorial          By: odwa at 2008-02-29 02:44:19

6. when i tried this code i couldnt run the program..
View Tutorial          By: kavitha at 2009-11-28 01:38:55

7. i got really nice help from the code. Thanks.
View Tutorial          By: Amit at 2009-04-10 08:18:40

8. Thanks it worked for me after lot of search for CO
View Tutorial          By: VIRAJ at 2012-12-26 11:56:24

9. great resource
View Tutorial          By: Anonymous at 2011-04-14 03:14:43

10. hi
Thanks great your tutorial. i want to wr

View Tutorial          By: fatima at 2009-08-29 00:15:27