Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Tuesday 11 December 2018

Frequency of letter in word in JAVA

PROGRAM



import java.util.Scanner;
public class DuplicateLetters{


public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
String letter = scan.next(); // Input from User

String srr[] = letter.split("");
for(int i = 0; i<srr.length;i++){
    int count = 1;
    if(!srr[i].equals("$")){
    for(int j = i+1; j<srr.length;j++){
       
        if(srr[i].equals(srr[j])) {
            srr[j] = "$";
            count++;
        }
    }
    System.out.println(srr[i] +" "+count);
    }
   
}


}

}

Input

BeginnersBook.com

Output

B 2
e 2
g 1
i 1
n 2
r 1
s 1
o 3
k 1
. 1

4 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Hey, your article is interesting. I will share with my friends. My colleagues were taking about cloudcouncil that they provide certification in Java. As you have knowledge in it can you help me is that worth studying and get certified ? https://cloudcouncil.org/

    ReplyDelete