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. can any body help to get the code for receiving SM
View Tutorial          By: ash at 2008-05-15 01:07:19

2. Hiiii Al, I am Ashraf Abu Aisheh, i am working to
View Tutorial          By: Ashraf Abu Aisheh at 2008-11-09 14:56:39

3. very good cod
View Tutorial          By: moly at 2007-03-13 08:17:40

4. can i use PrintWriter to save to a word document o
View Tutorial          By: philip at 2013-03-20 10:21:01

5. how to run this code....... Please tell somebody m
View Tutorial          By: Honey at 2015-01-24 14:27:38

6. Hi Ramalak,
My modem is connected to COM3 p

View Tutorial          By: divya at 2008-04-30 23:19:26

7. short notes to struts,but i expect more explanatio
View Tutorial          By: jayashri at 2011-11-23 18:24:07

8. Hello guys, I'm developing java program to send SM
View Tutorial          By: Rania at 2010-09-08 09:04:47

9. Hi there, I fixed the above (non-working) example
View Tutorial          By: JavaBoy at 2011-09-24 05:41:19

10. sir i m getting chat server started bt how a clien
View Tutorial          By: ashu at 2010-11-02 08:13:00