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
Java program to get location meta data from an image
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
Archived Comments
1. Hi I have a USB bluetooth that plug in my computer
View Tutorial By: venkat c s at 2008-07-21 12:15:46
2. i want simple program of function used in recursio
View Tutorial By: manish at 2009-05-19 01:03:19
3. Excelente!!
Justo lo que necesitaba.
View Tutorial By: Cesar at 2010-01-07 17:40:52
4. import java.util.*;
public class de
View Tutorial By: Virudada at 2012-05-05 06:27:22
5. How do i get tht GSM Connection .Can any one give
View Tutorial By: srinivas raju at 2008-08-08 02:50:02
6. hi, how do i turn it into a gui with swing allowin
View Tutorial By: psychicjava at 2011-02-06 13:18:08
7. I liked it.
View Tutorial By: savitha at 2011-05-06 02:23:46
8. Great!! Many thanks!
View Tutorial By: Louis at 2013-06-01 23:16:41
9. This is an excerpt from Java Complete Reference.Ju
View Tutorial By: Guest at 2010-03-25 01:36:57
10. I do not understand this line:
Map.Entry me
View Tutorial By: hap Og at 2011-11-03 01:42:33