Question: Huffman Coding can you give me a code that can count how many characters is repeated in the text inputted. Sample is like this: Inputted

Huffman Coding

can you give me a code that can count how many characters is repeated in the text inputted.

Sample is like this:

Inputted Text:

HAAHAABAAACACAAAABABABEBEBBAABEEBBCCCCCAAAAAAACCCDDDDDDAAADDDDDEEEEEEDDADDDADDEEEEEEEECCCEEEEEEEEEEDDEEEEEEEEEEBBEEEEEFFGGHAHHEEHHA

Output is:

Character Number of occurrence of the character in the text

A 30

B 12

C 13

D 20

E 45

F 2

G 2

H 7

my code is this:

import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class HuffmanTable { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Input a series of characters to be converted into Huffman code"); System.out.print("Input: "); String input = keyboard.nextLine(); ArrayList chars = new ArrayList<>(); // Iterates through the input for (int i = 0; i < input.length(); i++) { // If ArrayList is empty add the current character to the list if (chars.isEmpty()) { chars.add(input.charAt(i)); } else if (!chars.contains(input.charAt(i))){ chars.add(input.charAt(i)); } else { } } Collections.sort(chars); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!