Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Brackets balancing
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { String input = "a(((b+c)+d)"; char[] c = input.toCharArray(); char[] x = new char[c.length]; int top=-1; for(int i=0;i<c.length;i++){ if(c[i] == '('){ top=top+1; x[top]=c[i]; } else if(c[i] == ')'){ top=top-1; } } if(top==-1){ System.out.println("Brackets are balanced"); } else System.out.println("Brackets are not balanced"); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
jb11.0 threads tick tock 1.0
has a
1.6
Rotate matrix clockwise
Array - char
Problem: rstring
String is not reference Type??
Info by dfs
1a
Kochergina
Please log in to post a comment.