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. Hi Ramlak
I am trying to run your code.

View Tutorial          By: jainitya at 2011-05-04 12:26:16

2. sir, in this example,which value of n is being sto
View Tutorial          By: shivom at 2012-01-15 07:16:49

3. at
OK
at+cmff=1
OK
at+

View Tutorial          By: shrinivas at 2009-03-07 23:16:51

4. I can not understand left shift operater ,i am a f
View Tutorial          By: umar at 2012-01-31 12:28:11

5. hi can any one help me how i can install javax.co
View Tutorial          By: Jewel at 2008-02-26 21:52:17

6. So simple..Very easy to understand
View Tutorial          By: G.Tejasree at 2011-11-05 11:51:38

7. There is 3rd Party webservices hosted over HTTPS,
View Tutorial          By: Ankur at 2012-02-24 16:49:59

8. Hi,

I am getting error "Sender

View Tutorial          By: Jose at 2008-05-26 08:17:48

9. Dear Gurus, I have arrived at your site lloking f
View Tutorial          By: Fred Mah at 2012-09-22 07:40:27

10. hey..
shouldn't the 2nd java code have an o

View Tutorial          By: izzie at 2010-04-06 11:34:34