Comment on Tutorial - Stack example in Java - push(), pop(), empty(), search() By Henry



Comment Added by : srikanth

Comment Added at : 2014-05-30 06:44:58

Comment on Tutorial : Stack example in Java - push(), pop(), empty(), search() By Henry
import java.io.*;
import java.util.*;
class Stackdemo
{
public static void main(String []args)throws IOException
{
Stack<Integer> st=new Stack<>();
Buffer Reader br =new Buffer Reader(new InputStreamReader(System.in));
int element,pos,choice=0;
while(choice<4)
{
System.out.println("stack operation");
System.out.println("1 push element");
System.out.println("2 pop element");
System.out.println("3 search for element");
System.out.println("4 exit");
System.out.println("your choice");
choice=Integer.parseInt(br.readline());
switch(choice)
{
case1:
System.out.print("enter element:");
element =Integer.parseInt(br.readline());
st.push(element);
break;
case2:
Integer i=st.pop();
System.out.print("poped="+i);
break;
case3:
System.out.print("enter element");
element=Integer.parseInt(br.readline());
pos=st.search(element);
if(pos==-1)
System.out.println("element not found");
else
System.out.println("element found position:"+pos);
break;
default;
return;
}
System.out.println("Stack="+st);
}
}
}




}


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. it was very useful to me
View Tutorial          By: balaji at 2012-01-09 22:50:25

2. i am getting following error

Error

View Tutorial          By: Pavan at 2009-11-26 21:31:22

3. To "need help":

String st

View Tutorial          By: alex at 2010-05-13 09:57:25

4. send java examples of all topics
View Tutorial          By: Ruthraganesh at 2008-06-11 22:06:11

5. Hi, I have mobile application developed in java w
View Tutorial          By: Meenu at 2008-12-30 02:46:54

6. The above example for abstract class is very good.
View Tutorial          By: saafia at 2013-08-19 14:33:54

7. Would u please provide me with a solution about ho
View Tutorial          By: milan at 2011-02-17 05:39:38

8. dear sir ,
How can i create my smtp or host

View Tutorial          By: jignesh at 2011-03-14 01:42:11

9. Simplified explanation with perfect Examples
View Tutorial          By: Sushant Chaudhary at 2010-07-12 00:32:18

10. can u pls tell me how to retrive data from databas
View Tutorial          By: yogesg desai at 2010-05-27 08:26:24