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 so much for the tutorial!! Was extremely us
View Tutorial          By: Debarupa at 2012-05-10 20:23:28

2. had the sample problem.. java.io.IOException: HTTP
View Tutorial          By: java at 2012-08-22 09:39:57

3. if i wanna push the data from my keyboard input, h
View Tutorial          By: andys at 2008-11-09 03:09:32

4. plz send inheritance concept,how to use final,thi
View Tutorial          By: sobha at 2010-02-14 08:29:33

5. Si AIZA DIN< DI MARUNONG MAGTURO
View Tutorial          By: Agnes at 2010-06-25 22:34:29

6. Hi
I can compile it
root$ javac -cp

View Tutorial          By: Tebogo Modiselle at 2014-10-31 08:47:09

7. Good ,I like here&#65281; I send gmail with j
View Tutorial          By: jackhexl at 2009-04-02 03:29:44

8. Hai,
I have stil problem with generate XML

View Tutorial          By: Priyan at 2009-04-06 12:08:42

9. very thanks... It's very useful to me...
Th

View Tutorial          By: swathi. M at 2015-01-02 16:32:19

10. Hi, I am getting following exception while running
View Tutorial          By: Vasundhra at 2008-06-24 07:04:42