Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BracketsCheck
- {
- static void Main()
- {
- string expression = "((a+b(/5-c)";
- int opened = 0;
- int closed = 0;
- for (int i=0; i<expression.Length; i++)
- {
- if (expression[i].Equals('('))
- {
- opened++;
- }
- else if (expression[i].Equals(')'))
- {
- closed++;
- }
- }
- Console.WriteLine("There are {0} open breckets and {1} close bracker into the expression!", opened, closed);
- if (opened==closed)
- {
- Console.WriteLine("=> The expression is correct!");
- }
- else
- {
- Console.WriteLine("=> The expression is wrong!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement