-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathFind_CountWord.java
39 lines (36 loc) · 968 Bytes
/
Find_CountWord.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
/* Input : Home, Sweet Home
Home
* Output : Number of that word present in the sentence : 2
*
* Process
* ----------
* The word Home present in the sentence 2 times
*/
import java.util.*;
public class Find_CountWord
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] arr = str.split(" ");
String s = sc.nextLine();
String ch = "";
int count = 0;
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[i].length(); j++)
{
if(Character.isLetter(arr[i].charAt(j)))
{
ch = ch + arr[i].charAt(j);
}
}
if(ch.equals(s))
{
count++;
}
ch = "";
}
System.out.println("Number of that word present in the Sentence : "+count);
}
}