Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given an array of strings, write a function mostFrequentStrings(String[] in) usi

ID: 3756105 • Letter: G

Question

Given an array of strings, write a function mostFrequentStrings(String[] in) using your implementation of Class HashtableChaining that computes the frequency of each string and returns an array of strings consisting of the 5 most frequent strings. You have to do this using the provided Pair class. Again, the strings will be combinations of lowercase and/or uppercase characters delimited by a newline character.

class Pair<K,V>

{

/*

The Pair class is intended to store key, value pairs. It'll be helpful

for part 1.2 of the assignment.

*/

public K key;

public V value;

public Pair(K key, V value)

   {

this.key = key;

this.value = value;

   }

}

Explanation / Answer

import java.util.Scanner;

public class JavaProgram
{
public static void main(String args[])
{
int ci, x, y, k, l=0;
String s1, s2;
char ch, chr;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a String : ");
s1=scan.nextLine();
  
x=s1.length();
for(ch='A'; ch<='z'; ch++)
{
k=0;
for(y=0; y<x; y++)
{
chr = s1.charAt(y);
if(chr == ch)
{
k++;
}
}
if(k>0)
{
System.out.println("The character " + ch + " has occurred for " + k + " times");
}
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote