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

What is the difference between yielding and sleeping in java programming?

586


What is += mean in java?

545


What is variable and rules of variable?

520


Define Multiprogramming and Multiprocessing in java.

581


What is meant by flickering?

656






Describe string intern() methodology

595


What does this () mean in java?

547


Explain different types of thread priorities ?

626


What is general methodology?

571


What is immutable class in java?

514


Explain about core java?

626


Can you pass functions in java?

568


What are format specifiers in java?

596


How many types of methods are there?

548


What are static methods?

576