// Java program to count the number // of occurrence of a word in // the given string given string import java.io.*; class GFG { static int countOccurences(String str, String word) { // split the string by spaces in a String a[] = str.split(" "); // search for pattern in a int count = 0; for (int i = 0; i < a.length; i++) { // if match found increase count if (word.equals(a[i])) count++; } return count; } // Driver code public static void main(String args[]) { String str = "GeeksforGeeks A computer science portal for geeks "; String word = "portal"; System.out.println(countOccurences(str, word)); } } |
Subscribe to:
Post Comments (Atom)
40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot
40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot 1. What is Tight Coupling? When a class (ClassA) is depen...
-
ITV-JDBC-Why we use Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database?1) Why we use Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database? https://stackoverflow.com/questions/2007858...
-
1. Introduction In Spring MVC, the DispatcherServlet acts as front controller – receiving all incoming HTTP requests and processing ...
-
Table - EmployeeDetails EmpId FullName ManagerId DateOfJoining 121 John Snow 321 01/31/2014 321 Walter White 986 01/30/2015 421 Kuldee...
No comments:
Post a Comment