program logic:
program:
import java.util.*;
import java.io.*;
public class Test {
public static int factorial(int n){
int prod = 1;
for(int i = 1; i<=n; i++)
prod *= i;
return prod;
}
public static int countOccurences(String str){
HashMap<Character, Integer>
charCountMap = new HashMap<Character, Integer>();
char[] strArray =
str.toCharArray();
for(char c: strArray){
if(charCountMap.containsKey(c))
charCountMap.put(c,
charCountMap.get(c)+1);
else
charCountMap.put(c,1);
}
int numer =
factorial(str.length());
int denom = 1;
for(int value:
charCountMap.values()){
denom *=
factorial(value);
}
return numer/denom;
}
public static void main(String[] args){
String str = "AAAB";
int permute =
countOccurences(str);
System.out.println("Return value:
"+permute);
}
}
output:
Write code in Java. In this step, functions and methods are synonymous. You may assume that...
WRITTEN IN JAVA Write a function as follows: Receive a string as a parameter.Count the length of the string.Count the occurrences of each distinguishable symbol in the string (use an array).Divide the factorial of the length by the product of the factorials of the occurrences.Return the quotient as the integer result.The point of this function is to find the result only by using the formulas for permutations.For example, BAAA the function counts that the string length is 4, that A...
Write a function decompressed(count_tuples) that takes a list of counts of '0's and '1's as defined above and returns the expanded (un-compressed) string. You may assume that the first value of count_tuples has a count that is greater than or equal to zero and all other counts are greater than zero. Comments to show how to figure this out would be greatly appreciated A data file in which particular characters often occur multiple times in a row can be compressed...
For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...
‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...
Overview: file you have to complete is WordTree.h, WordTree.cpp, main.cpp Write a program in C++ that reads an input text file and counts the occurrence of individual words in the file. You will see a binary tree to keep track of words and their counts. Project description: The program should open and read an input file (named input.txt) in turn, and build a binary search tree of the words and their counts. The words will be stored in alphabetical order...
Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...
Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...
pUI) FOU are to write a function which has a prototype: void count (char sl, int *pUpper, "pLower, "poigit, pother) s [ is a character string which may be of any length. Other arguments are address of where the number of upper, lower, digits, and other characters in the string should be placed. For example (this is only an example) the code (put into a properly written program): char all "12145-9ABD, 3f0 :bbB2" char bll "148x3!!" char c[] = {...
PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is a run of 10 A’s. We could encode this run using a notation like *A10, where the * is a special flag character that indicates a run, A is the symbol in the run, and 10 is the length of the run. As another example, the string KKKKKKKKKKKKKBCCDDDDDDDDDDDDDDDKKKKKMNUUUGGGGG would be encoded...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...