-
Notifications
You must be signed in to change notification settings - Fork 0
/
GFG.java
40 lines (40 loc) · 868 Bytes
/
GFG.java
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
package practicetime;
import java.util.*;
import java.lang.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
String s=sc.next();
String s1="";
String s2="gfg";
int c=0;
for(int j=0;j<s.length()-2;j++)
{
s1=s1+s.charAt(j);
for(int k=j+1;k<(j+3);k++)
{
s1=s1+s.charAt(k);
}
//System.out.println(s1+" and "+s2);
if(s1.equals(s2)==true)
{
c++;
//System.out.println(c);
}
//System.out.println(c);
s1="";
}
if(c>0)
{
System.out.println(c);
}
else if(c==0)
{
System.out.println(-1);
}
}
}
}