Below is the code:
import java.util.*;
import java.io.*;
public class MyClass {
public static void main(String args[])
{
Scanner scn = new Scanner(System.in);
String str = scn.nextLine();
String[] arr = str.split(" ");
for(int i =0; i<arr.length; i++)
{
int count = 0;
for(int j =0; j<arr.length; j++)
{
if(arr[i] == arr[j])
{
count++;
}
}
System.out.print(count + " ");
}
}
}
How can I count each value of a repeated word in a string?