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
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
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
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program 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
Archived Comments
1. Thanks so much for the tutorial!! Was extremely us
View Tutorial By: Debarupa at 2012-05-10 20:23:28
2. hi all m getting following error ,
can anyo
View Tutorial By: raj at 2008-11-04 21:46:12
3. I am still going through the tutorial, but it seem
View Tutorial By: shadowwraith at 2011-06-08 08:00:57
4. Sir , I am doing B.Tech . I want to know more abou
View Tutorial By: amita saini at 2011-08-05 13:07:35
5. M having query
i wat to create employee cla
View Tutorial By: Dayasagar at 2010-05-22 16:18:17
6. Thnaks a lot. Deep in brief.
View Tutorial By: Thanks at 2012-05-23 03:36:37
7. Thankyou it is Working Fine .....
View Tutorial By: PDCOE at 2009-02-11 23:02:29
8. Hi Steve.
I have two applications; 1 listen
View Tutorial By: Victor at 2010-08-18 01:22:49
9. java program to maintain the books details like Bo
View Tutorial By: Prabha at 2013-08-28 12:34:00
10. Nice explanation!!!!!!! thank you
View Tutorial By: Dinesh at 2013-07-21 10:33:30