java - count the frequency of letters in given word -


I need help writing a program about counting how frequently the given word has been repeated . Lower and upper case are equal to letters and they also have to work for numbers. For example:

We have to use array and loop. Also, if more than 1 word / number is given, then that place should not be counted and if the users want to continue or not, then they should enter the dot. 'Or when there is a dot'. After the word, it should close the program after counting the letters.

University = e: 1 i: 2 n: 1 r: 1 s: 1 t: 1 u: 1 y: 1

  Import java.util.Scanner ; Import java.lang.Character; Public category array {public static zero main (string [] args) {scanner input = new scanner (System.in); Int [] letters = new int [26]; String str = input.nextLine (); str = str.toLowerCase (); For (int i = 0; i & lt; str.length (); i ++) {letter [i] = 0; } System.out.println (str.length ()); Println (char2int ('a')); System.out.println (char2int ('D')); } Public static char charint (char c) {return character. Liver Cas (C) - (Int) 'A'; }}   

It comes out, for example me
2


3

I'm going to give you a big sign, what you need to do is a method (say countLetters ) and a word It takes a letter - so it will be, count

  // in the word "letter" (word). Public static int calculation liter (string word, four letter) {int count = 0; If (word! = Null) {char lc = character. Liver Cas (letter); For (four c: word kocharare ()) {if (lc == character. Liver cas (c)) {count ++; }}} System.out.printf ("% s:% d \ n", String.valueOf (letter), counting); Calculation of return; } Public static zero main (string [] args) {string test = "universe"; CountLetters (test, 'E'); CountLetters (test, 'u'); }   

is output

  E: 2 U: 1    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -