Created
April 17, 2020 22:24
-
-
Save so77id/b5650d0d5b0fc1fd0888dbff9508305c to your computer and use it in GitHub Desktop.
Stack example in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; // Import the Scanner class | |
import java.util.Stack; | |
public class StackExample { | |
public static void main(String[] args){ | |
int n; | |
String buff; | |
Scanner scanner = new Scanner(System.in); // Create a Scanner object | |
Stack<String> stack = new Stack<String>(); | |
n = scanner.nextInt(); | |
for(int i=0; i<n; i++) { | |
buff = scanner.next(); | |
stack.push(buff); | |
} | |
while(!stack.empty()) { | |
System.out.println(stack.pop()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment