I am trying to figure out how to write this code using recursion. I have done it sing for loops but have absolutely no clue how to use recursion here. I am new to code.Thanks for stopping by and helping.
P.S.
Sorry if i didnt explain what this does. The objective is to find out how many matching pairs of parenthesis exist in a given string input. It should also return -1 if a set is unbalanced.
These are the instructions
Classes names.

MatchingBracesFirstNameLastName.java
Stack.java
Description.

Write a program to match parenthesis (), square braces [] and curly braces {}. Your program should use a recursive method that returns the number of pairs of each type of brace and return -1 if it is unbalanced for a particular pair. You should also create a Stack class that will be used by the method to match braces. 

```
import java.util.*;

public class MatchingBraces
{
   public static void main(String []args)
   {
      Scanner input = new Scanner(System.in);
      String text = input.nextLine();
      System.out.println(match(text, '(', ')', 0));
      System.out.println(match(text, '[', ']', 0));
      System.out.println(match(text, '{', '}', 0));
   }

   public static int match(String text, char open, char close, int startIndex)
   {  
      Stack<Character> stack = new Stack<Character>();
      int count = 0;
      char c;
      for(int i = 0; i < text.length(); i++)
      {
         c = text.charAt(i);
         if(c == open)
            stack.push(c);

         if(c == close)
         {
            if(stack.empty())
               return count;
            else if(stack.peek() == open)
            {
               stack.pop();
               count++;
            }
         }
      }
     return count;
   }
}

```