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



Ask a Question

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. Good example...easy to read and understand...
View Tutorial          By: Codventure at 2009-09-11 00:07:06

2. at
OK
at+cmff=1
OK
at+

View Tutorial          By: shrinivas at 2009-03-07 23:16:51

3. Good example for vector
View Tutorial          By: mangai at 2011-07-07 09:46:10

4. how to read csv file using Java
View Tutorial          By: Shireesha at 2013-12-26 07:34:22

5. Nice explaination.. But wats the use of it? Can i
View Tutorial          By: kavita at 2013-04-04 07:10:14

6. more info needs to be given ............
View Tutorial          By: sufficient for new commer at 2008-05-09 00:41:58

7. HELP! HELP! HELP!
i got an time out at step

View Tutorial          By: sumit at 2009-04-03 20:19:51

8. Thank you ... was very helpfull indeed !!
View Tutorial          By: Avinav at 2011-02-09 15:46:37

9. if i want to write my gmail address how can i prov
View Tutorial          By: asmcn at 2011-12-27 19:40:49

10. sir very well subject is to continuted the java s
View Tutorial          By: G.venkata siva naga kumar at 2009-11-06 01:13:02