-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrepeated-character.java
More file actions
42 lines (40 loc) · 1.01 KB
/
repeated-character.java
File metadata and controls
42 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.lang.*;
import java.io.*;
import java.util.*;
class GFG
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int z=0;z<t;z++)
{
String str=sc.next();
int l=str.length();
int count=0;
int j;
char c='a';
for(int i=0;i<l;i++)
{
count=0;
for(j=i+1;j<l;j++)
{
if(str.charAt(i)==str.charAt(j))
{
c=str.charAt(i);
count++;
}
}
if(count>0)
{
System.out.println(c);
break;
}
}
if(count==0)
{
System.out.println("-1");
}
}
}
}