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 bro...you save me from a great problem...ve
View Tutorial          By: Tishan at 2012-07-09 09:14:07

2. string strInsert = "Insert into [Sheet1$](F1,
View Tutorial          By: Sagar at 2011-05-12 06:47:13

3. it giving me error in following statment (using wi
View Tutorial          By: prathamesh at 2007-03-16 05:57:20

4. Friends i m getting error while intrepreting the e
View Tutorial          By: Hanuman at 2014-02-04 14:14:00

5. dat is wat i want to jegay with you ,......dats ko
View Tutorial          By: dorji wangmo at 2011-12-27 05:38:35

6. Bitwise OR is a pipe (|), not a logical NOT (!)
View Tutorial          By: Martijn at 2011-06-21 10:49:29

7. Thank you so much for this. This helped me through
View Tutorial          By: GeeAsphyxiated at 2009-08-31 08:03:07

8. while compiling above program, iam getting this ER
View Tutorial          By: ss chary at 2013-07-15 08:06:18

9. its so nice
View Tutorial          By: senthilkumar at 2010-11-11 02:44:37

10. please explain thread t=new thread(this,name). Wha
View Tutorial          By: Bhavin at 2012-09-28 12:26:55