Menu
Topics Index
...
`

Create a letter count string for the given input string


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to create a letter count string for the given input string.

Input (String) Output (String)
MERITCAMPUS A1C1E1I1M2P1R1S1T1U1
CHILDREN C1D1E1H1I1L1N1R1
POTATO A1O2P1T2
CRICKET C2E1I1K1R1T1
DDDAAAFFFBBE A3B2D3E1F3
ZZZZZZZ Z7
CAMEROON A1C1E1M1N1O2R1


import java.util.*;
class LetterCounter
{
    public static void main(String s[])
    {
        String inputWord = "MERITCAMPUS";
        System.out.println(createLetterCountString(inputWord));

    }


    public static String createLetterCountString(String inputWord) {
    }
    

}
Topic: Java Character Extraction - toCharArray() Method In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

To create Letter count String we need to use "Nested For Loops"

1)first Loop will have character counter starting with 'A' and run till 'Z'.

2)second Loop will have have integer counter starting with 0 till the length of inputString.

inside this secondLoop we will check every character of string with letter 'A'.if they are equal we will increase the counter.
Outside this Loop when count for the particular letter is done we will check if count>0 then we will concatinate the letter(represented by outer loop counter)with count.Same procedure will be applied for each character from 'A' to 'Z'.

At last we will return the resultant string.

Posted by Mânïshå Mùlchåndânï    2014-12-31 09:53:15


Here first we need to find the Uniquestring by removing the duplicates...CRICKET--CRIKET
Step1:

Write additional method to find it..
take an String temp variable add 1st char to it...than start loop add every char
to it...before adding check whether the char is there r not..if is there dont
add..we can find it using contains()
if(!temp.contains(""+input.charAt(i))

than Sort the String Arrays.sort() method

Step2:
start for loop for travelling through the unique string
i=0;i<uniqueString.length();i++

take another loop travelling through the Input string

if the char in uniqueString occurs in the input string than increas thr
counter..
j=0;j<input.length();j++
if charAt(i)==charAt(j)
counter++;

after coming out of the inner loop add the char and count to the result
variable
temp+=charAt(i)+counter;
than initialize the counter=0

Posted by Uday Kumar    2015-01-01 04:35:42


This dose is now closed and the winners are Mânïshå Mùlchåndânï,  for 'First Correct Comment', Uday Kumar,  for 'Second Correct Comment'. The 'lucky liker' is Puneeth Shivalingaiah. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-03 05:14:32


© meritcampus 2019

All Rights Reserved.

Open In App