For this Question: You are given a string S (containing only lowercase characters). You need to print the repeated character whose first appearance is leftmost.The first line of input contains T denoting the number of testcases. T testcases follow. 
Each testcase contains one line of input containing the string S.

Constraints:
1 <= T <= 100
1 <= |S| <= 1000For each testcase, in a new line, print the character. If not found then print "-1".Input:
2
geeksforgeeks
abcd

Output:
g
-1

Explanation:
Testcase1: We see that both e and g repeat as we move from left to right. But the leftmost is g so we print g.
Testcase2: No character repeats so we print -1.
 , I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.*;

class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        
        while(t-- > 0)
        {
            String str = sc.next();
            int index = repeatedCharacter(str);
            if(index == -1)
                System.out.println("-1");
            else
                System.out.println(str.charAt(index));
        }
    }
    static int repeatedCharacter(String S)
    {
        // Initialize leftmost index of every 
        // character as -1. 
        int firstIndex[]= new int[256]; 
        for (int i = 0; i <256; i++) 
            firstIndex[i] = -1; 
      
        // Traverse from left and update result 
        // if we see a repeating character whose 
        // first index is smaller than current 
        // result. 
        int res = Integer.MAX_VALUE; 
        for (int i = 0; i < S.length(); i++) { 
            if (firstIndex[S.charAt(i)] == -1) 
               firstIndex[S.charAt(i)] = i; 
            else
               res = Math.min(res, firstIndex[S.charAt(i)]); 
        } 
      
        return (res == Integer.MAX_VALUE) ? - 1 : res;
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?