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. very simple explanation......
easily unders

View Tutorial          By: saurabh at 2009-04-17 16:02:30

2. if the number is for exemple 00025478 it return a
View Tutorial          By: ahmed at 2015-02-11 12:02:45

3. Very simple and easy to understand... Thank u...
View Tutorial          By: Anu Priya at 2013-07-22 09:00:19

4. I am very much thankfull to you in providing the c
View Tutorial          By: c vijaychandar at 2010-05-05 10:14:59

5. good explanation
View Tutorial          By: Naresh Kumar at 2010-10-25 00:28:18

6. good going java samples
View Tutorial          By: Rajesh at 2010-08-17 03:36:12

7. thank you..........
View Tutorial          By: ravi at 2010-01-29 23:27:39

8. i need a source to send and receive SMS through th
View Tutorial          By: morteza at 2010-03-03 01:53:09

9. I did this exactly.
In my case, the fix.php

View Tutorial          By: Manorasa at 2010-06-29 23:32:24

10. nice///
View Tutorial          By: MHARLON ALADEN at 2009-08-14 01:00:09