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. Hi , instead of using localhost. I am using a mobi
View Tutorial          By: vimal at 2010-12-02 01:44:40

2. I'm sorry I've misunderstood, join() guarantees th
View Tutorial          By: Junkie Zhang at 2012-01-10 06:02:00

3. please someone share the example to receive messag
View Tutorial          By: yem at 2013-04-06 01:52:00

4. i am newly in java, i want to learn about this and
View Tutorial          By: gelen at 2010-11-23 02:57:15

5. Thanks for giving iterator example
View Tutorial          By: Rajesh Kumar at 2010-11-03 05:17:05

6. could you please send me a complete appointment re
View Tutorial          By: Jaylon aron at 2010-02-21 02:22:57

7. wow amzing
View Tutorial          By: Anonymous at 2009-04-23 01:44:43

8. I tried this with HttpUnit (using the custom Hostn
View Tutorial          By: Michael Gower at 2012-01-04 17:40:00

9. Hi

Where puts this code in ror app

View Tutorial          By: martin at 2013-01-31 08:51:12

10. Good examples for beginners.
View Tutorial          By: Sagar at 2009-10-16 01:04:46