Computer Science, asked by ziyaali1289, 1 day ago

Create a program that reads a line and a substring. It should then display the number of occurrences of the given substring in the line.​

Answers

Answered by p963096
1

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner Sc = new Scanner(System.in);

String sentence , word;

System.out.print("Enter a sentence : ");

sentence = Sc.nextLine();

System.out.print("Enter a word : ");

word = Sc.next();

String a[] = sentence.split(" ");

int count = 0;

for(int i = 0 ; i < a.length ; i++)

{

System.out.println(a[i]);

if(word.equalsIgnoreCase(a[i]))

{

count++;

}

}

System.out.print("Word count = " + count);

}

}

Similar questions