Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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(); ArrayListchars = 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started