OneCompiler

How to count and print the no of times the string(hg) has repeated in a string in java by Jayanthi ganesh

186

import java.util.*;

public class CountString {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String s1=sc.nextLine();
System.out.print(s.split(s1,-1).length-1);
}

}