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. thanks a lot that helped.. =D
View Tutorial          By: Karthik at 2008-11-16 02:27:53

2. Hi,
i am working on ocap xlet project. here

View Tutorial          By: swati at 2012-07-09 08:39:13

3. can u give me the example simulation of strcat??
View Tutorial          By: farah at 2009-10-05 01:10:02

4. Thank ... for idea But
i m confuse how run

View Tutorial          By: Tanaji at 2010-06-01 23:13:19

5. is there any way to generate report without seagat
View Tutorial          By: Roshni at 2012-10-01 09:32:41

6. Ask to google.
View Tutorial          By: John at 2013-05-03 22:58:23

7. is there any port filter/block api for java?
View Tutorial          By: edwin at 2010-08-12 03:16:44

8. When trying to install Java

i was

View Tutorial          By: Sinmo at 2009-08-30 00:31:33

9. Sir!
I want the source code for receiv

View Tutorial          By: Anupam Shukla at 2010-04-30 00:09:25

10. Would be great if you also showed how to manipulat
View Tutorial          By: Sparx at 2010-01-05 13:51:56