Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nomor02;
- import java.util.*;
- class Verification {
- static boolean pairCharacters(Stack<String> a) {
- Stack<String> help = new Stack<String>();
- while (!a.isEmpty()) {
- help.push(a.peek());
- a.pop();
- }
- while (help != null) {
- String x = help.peek();
- help.pop();
- String y = help.peek();
- help.pop();
- if ((x!="/*" && y!="*\\")
- || (x!="(" && y!=")")
- || (x!="[" && y!="]")
- || (x!="{" && y!="}"))
- return false;
- }
- return true;
- }
- public static void main(String[] args) {
- Stack<String> a = new Stack<String>();
- a.push("/*");
- a.push("*\\");
- a.push("(");
- a.push(")");
- a.push("[");
- a.push("]");
- a.push("{");
- a.push("}");
- if(pairCharacters(a))
- System.out.println("YEAH:)");
- else
- System.out.println("NOPE:(");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment