-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchingBrackets1.java
More file actions
27 lines (23 loc) · 871 Bytes
/
Copy pathMatchingBrackets1.java
File metadata and controls
27 lines (23 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package StacksAndQueues_Lab;
import java.util.ArrayDeque;
import java.util.Scanner;
public class MatchingBrackets1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
ArrayDeque <Integer> stack = new ArrayDeque<>();
for (int i = 0; i < input.length() ; i++) {
char symbol = input.charAt(i);
//char current = stack.peek();
if (symbol == '(') {
stack.push(i);
} else if (symbol == ')') {
// char currentSymbol = stack.peek();
int startIndex = stack.pop();
// int endIndex = symbol + 1;
String content = input.substring(startIndex, i + 1);
System.out.println(content);
}
}
}
}