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. sr
thanks 4 information provided
b

View Tutorial          By: veer kumar at 2012-07-25 18:30:38

2. Nice one for jsp learners.
View Tutorial          By: Vignesh at 2011-07-14 04:04:55

3. This will give the output check it out


View Tutorial          By: shruthi at 2013-01-18 06:00:08

4. as we write:
ob1.t.join();
Does t

View Tutorial          By: abc123 at 2011-04-03 13:33:33

5. thanks a lot............
View Tutorial          By: mks at 2013-01-03 06:50:05

6. Hi mounika, Did you download and install the javac
View Tutorial          By: Ramlak at 2008-04-27 05:49:42

7. great work..keep it up.
View Tutorial          By: faizaan at 2011-04-29 12:23:39

8. Hi,
Any body tell me how to these execute t

View Tutorial          By: mari at 2009-07-09 02:02:12

9. Please send the complete code.. thanks!
View Tutorial          By: Roger22 at 2010-03-11 00:41:07

10. I want simple programs using BuffuredReader for m
View Tutorial          By: Why ask my name? at 2013-06-01 04:56:00