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. nice///
View Tutorial          By: MHARLON ALADEN at 2009-08-14 01:00:09

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

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

3. good start up fr java beginers
View Tutorial          By: sandeep Ch at 2012-01-06 07:16:34

4. Nice Example.Good work.keep it up.
Thanks,<

View Tutorial          By: Lucky at 2011-07-08 10:36:38

5. Hi,
I am getting this exception..My modem i

View Tutorial          By: puneet at 2010-04-22 10:22:18

6. EXACTLY COPIED BY "C PROGRAMMING" by DEN
View Tutorial          By: Aashish at 2012-06-06 17:56:36

7. very nice example
View Tutorial          By: harshal at 2013-02-06 09:34:10

8. The synchronization schedule function has been red
View Tutorial          By: Kim at 2014-11-12 10:52:13

9. i am run this code changing the SMSC (ex:+9198860
View Tutorial          By: sknand13 at 2007-11-16 03:27:52

10. Hi every one. I am working on my project in j2me a
View Tutorial          By: wazir at 2010-11-26 08:27:43