Answer:
The following are the program to the given question:
import java.util.*;//import package for user input
public class Make //define class Make
{
public static void main(String[] ask) //define a main method
{
Scanner obx = new Scanner(System.in); //declare the Scanner class object
int size=obx.nextInt(); //get the size of the array from the user
int a[]=new int[size]; //declare an integer array with given size
String word[]=new String[size]; //declare a string array with given size
for(int i=0;i<size;i++) //set the for loop
word[i]=obx.next(); //get string input from the user
for(int i=0;i<size;i++) //iterates with the array, increase the count
{
for(int j=0;j<size;j++) //defining a loop to check value
{
if(word[i].equals(word[j])) //use if to check that elements of words
a[i]++;//increamenting array size
}
}
System.out.print("\n"); //use print for break line
for(int i=0;i<size;i++)//set for loop to print the following result
System.out.println(word[i]+" "+a[i]);//print value
}
}
Output:
Please find the attachment file.
Explanation:
- First, establish the predefined package required and instead define the main class and define the main method within the class and method.
- Declare the scanner class object and receive an object size in the 'size' variable thru the array.
- Next create two arrays, the integer type "a" with both the input size given and the string type "word" with the input size supplied.
- Define the loop for which string array elements are acquired and set two to again for loop, which increases with loop iteration the integer data type array by one.
- Lastly, set the loop for which this result is printed.