Write program to print Hello World and print each character
address in that string and print how many times each
character is in that string?
Ex: H: 0 & 1
e:1 & 1
l :2,3,8 & 3
o:4,6 & 2
w:5 & 1
r: 7 & 1
d 9 & 1

Answer Posted / binoy

I would make it simple.

public void printHello()
{

String s="Hello Good Morning";
int i=0;
for (char c: s.toCharArray())
{
System.out.print
(""+c+":"+i+count(c,s)+"\t");
i++;
}

}

public int count(char c, String s)
{
int index=-1;
int count =0;
while((index=s.indexOf(c+""))!=-
1)
{
s=s.substring(index+1);
count++;
}
return count;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to perform binary search in java?

566


difference between byte stream class and character stream class?

4075


What does method mean?

506


What is binary search in java?

553


What is the difference between a method and a procedure?

539






what is daemon thread and which method is used to create the daemon thread? : Java thread

520


What are the benefits of java?

565


What is methodological theory?

520


What is unicode datatype?

521


What is the common usage of serialization? What exceptions occur during serialization?

596


Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.

524


What is the main method java?

526


Which is the best sorting technique in java?

515


In the below example, what will be the output?

588


How do you check if a character in a string is a digit or letter?

501