Question:
Please help me to solve this simple Java program. Class X question?
?
2011-02-21 11:26:11 UTC
Write a simple java program to input a string in the parameter list and display the frequency of each letter in the string in alphabetical order.
For example, input - "committee"
output-
c 1
e 2
i 1
m 2
o 1
t 2



please please write it in simple programming format. Dont use too complex programming functions.
Thank you. It may come in my exam and i am unable to solve it.
Three answers:
Dan H
2011-02-21 11:33:28 UTC
Post your code and tell us what you have so far.
?
2016-12-01 13:34:20 UTC
createArray is a fashion. Is it additionally the call of your type? Is that the constructor? i anticipate that's the case, yet B isn't an array, that is an merchandise of the class createArray. you may enforce the [] operator to try this, yet i do no longer think of Java helps that overload. you may characteristic a fashion: public int itemAt( int i ) { return A[i]; } additionally, you have A as an area variable. that is going to likely be long gone as quickly as the constructor disappears. A could be a type member. Then, you get entry to it using B.itemAt(a million);
deonejuan
2011-02-21 11:57:05 UTC
public class AlphaFreqWArgs {



public static void main( String [] args ) {



if( args.length == 0 ) {

System.out.println("ERROR: usage -- java AlphaFreqWArgs myString");

System.exit(0);

}



char[] letters = args[0].toLowerCase().toCharArray();



String alphabet = "abcdefghijklmnopqrstuvwxyz";



int[] counts = new int[alphabet.length()];



for (int i = 0; i < letters.length; i++) {

int alphaLtrNo = alphabet.indexOf( letters[i] );

if( alphaLtrNo >= 0 )

counts[alphaLtrNo]++;



}

for (int i = 0; i < counts.length; i++) {

if( counts[i] > 0 )

System.out.println( letters[i] + " " + counts[i] );



}

}

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...