java count frequency of characters in a string
Java
public class Frequency
{
public static void main(String[] args) {
String str = "picture perfect";
int[] freq = new int[str.length()];
int i, j;
//Converts given string into character array
char string[] = str.toCharArray();
for(i = 0; i <str.length(); i++) {
freq[i] = 1;
for(j = i+1; j <str.length(); j++) {
if(string[i] == string[j]) {
freq[i]++;
//Set string[j] to 0 to avoid printing visited character
string[j] = '0';
}
}
}
//Displays the each character and their corresponding frequency
System.out.println("Characters and their corresponding frequencies");
for(i = 0; i <freq.length; i++) {
if(string[i] != ' ' && string[i] != '0')
System.out.println(string[i] + "-" + freq[i]);
}
}
}
Also in Java:
- Title
- how to convert a jsonobject to a dbobject
- Category
- Java
- Title
- excel data formatter in java
- Category
- Java
- Title
- java iterate through hashmap
- Category
- Java
- Title
- how to create java jframe in eclipse
- Category
- Java
- Title
- java instantiate collection with values
- Category
- Java
- Title
- java fileinputstream
- Category
- Java
- Title
- icon label java
- Category
- Java
- Title
- treeset java descending order using comparator
- Category
- Java
- Title
- logger in java
- Category
- Java
- Title
- thread sleep java
- Category
- Java
- Title
- creating the functional interface in java
- Category
- Java
- Title
- java define a generic class that produces
- Category
- Java
- Title
- find numbers in a string java
- Category
- Java
- Title
- how to count the number of occurrences of an element in a arraylist in java
- Category
- Java
- Title
- how to make stage dragable in javafx
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- java calculator code
- Category
- Java
- Title
- How to print in console java
- Category
- Java
- Title
- java read string input
- Category
- Java
- Title
- java remove duplicates
- Category
- Java
- Title
- java read integer from text file into array scanner
- Category
- Java
- Title
- how to create an array list in java
- Category
- Java
- Title
- java how to define a function
- Category
- Java
- Title
- transition java fx
- Category
- Java
- Title
- java fx display simple rectangle
- Category
- Java
- Title
- spigot spawn entity
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- get world by name bukkit
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- caesar cipher java
- Category
- Java
- Title
- ndroid.support.v4.content.FileProvider
- Category
- Java
- Title
- compile java to jar in mac
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- initialiser une arraylist
- Category
- Java
- Title
- java hashmap syntax
- Category
- Java
- Title
- how to use spring in java
- Category
- Java
- Title
- java find biggest number in array
- Category
- Java
- Title
- how to stop screen rotation in android code
- Category
- Java
- Title
- using java 8 stream to process data in java
- Category
- Java
- Title
- processing sound library
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- map.keyset in java
- Category
- Java
- Title
- count number of matches in two strings java
- Category
- Java
- Title
- taking string input in java
- Category
- Java
- Title
- java convert a set to array
- Category
- Java
- Title
- Compare integers java sort
- Category
- Java
- Title
- get tfidf score for a sentence
- Category
- Java
- Title
- Display double in decimal places java
- Category
- Java
- Title
- how to print in java
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- print a string java
- Category
- Java
- Title
- java comparable
- Category
- Java
- Title
- string to char in java
- Category
- Java
- Title
- java sql question mark
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- how to check wether the property exist in a object in java script
- Category
- Java
- Title
- how to parse a string into a number in java
- Category
- Java
- Title
- java 8 validate based on pair of strings
- Category
- Java
- Title
- déclarer un tableau en java
- Category
- Java
- Title
- java android edit text set value
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- treemap get order java
- Category
- Java
- Title
- enhanced for loop java
- Category
- Java
- Title
- iterate through hashmap in java
- Category
- Java
- Title
- long input in JAVA
- Category
- Java
- Title
- changing double space to single in java script
- Category
- Java
- Title
- how to cut a certion part from a string in java
- Category
- Java
- Title
- how to iterate hashmap in java
- Category
- Java
- Title
- java clear console
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- java download file from url to string
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- java script to detect and launch all browsers
- Category
- Java
- Title
- java insertion sort
- Category
- Java
- Title
- java sort array descending
- Category
- Java
- Title
- how to calculate min, max and average and write the output into into a text file in java
- Category
- Java
- Title
- android hide and show bottom navigation
- Category
- Java
- Title
- basic java coding
- Category
- Java
- Title
- android studio remove notification bar
- Category
- Java
- Title
- read a file in java and store as integer array using buffered reader
- Category
- Java
- Title
- check if value exists in hashset java
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- declareing a variable in java
- Category
- Java
- Title
- java square a number
- Category
- Java
- Title
- java int
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- java random number
- Category
- Java
- Title
- blurview android github
- Category
- Java
- Title
- how to pass parameters to xsl file
- Category
- Java
- Title
- how to declare a linked list in java
- Category
- Java
- Title
- java list of a class has a string that is equal to
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- java map iteration
- Category
- Java
- Title
- abs in java
- Category
- Java
- Title
- java find if element of list in present in another list
- Category
- Java
- Title
- fxmlloader getresource from another package
- Category
- Java
- Title
- height constraint layout guideline
- Category
- Java
- Title
- java treemap
- Category
- Java