String str = "javajavawoaijavahahajavaaiwo"; String s=str.repaceAll(java,""); int num = str.length()-s.length; System.out.println(num/4);