Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2.  
  3.     class BracketsCheck
  4.     {
  5.         static void Main()
  6.         {
  7.             string expression = "((a+b(/5-c)";
  8.             int opened = 0;
  9.             int closed = 0;
  10.            
  11.             for (int i=0; i<expression.Length; i++)
  12.             {
  13.                 if (expression[i].Equals('('))
  14.                 {
  15.                     opened++;
  16.                 }
  17.                 else if (expression[i].Equals(')'))
  18.                 {
  19.                     closed++;
  20.                 }
  21.             }
  22.             Console.WriteLine("There are {0} open breckets and {1} close bracker into the expression!", opened, closed);
  23.             if (opened==closed)
  24.             {
  25.                Console.WriteLine("=> The expression is correct!");
  26.             }
  27.             else
  28.             {
  29.                 Console.WriteLine("=> The expression is wrong!");
  30.             }
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement