snowcava

Nomor 2

Apr 19th, 2019
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package nomor02;
  2.  
  3. import java.util.*;
  4.  
  5. class Verification {
  6.  
  7. static boolean pairCharacters(Stack<String> a) {
  8.  
  9. Stack<String> help = new Stack<String>();
  10. while (!a.isEmpty()) {
  11. help.push(a.peek());
  12. a.pop();
  13. }
  14. while (help != null) {
  15. String x = help.peek();
  16. help.pop();
  17. String y = help.peek();
  18. help.pop();
  19. if ((x!="/*" && y!="*\\")
  20. || (x!="(" && y!=")")
  21. || (x!="[" && y!="]")
  22. || (x!="{" && y!="}"))
  23. return false;
  24. }
  25. return true;
  26. }
  27.  
  28. public static void main(String[] args) {
  29. Stack<String> a = new Stack<String>();
  30. a.push("/*");
  31. a.push("*\\");
  32. a.push("(");
  33. a.push(")");
  34. a.push("[");
  35. a.push("]");
  36. a.push("{");
  37. a.push("}");
  38. if(pairCharacters(a))
  39. System.out.println("YEAH:)");
  40. else
  41. System.out.println("NOPE:(");
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment