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 / rahul verma

public static void main(String... arg)
{
String str="Guriqbal Singh";
int length = str.length();
System.out.println(str.length());
String tempStr="";
for(int i =0;i<length;i++)
{
String out="";
char a = str.charAt(i);

if(tempStr.contains(""+a))
continue;
tempStr=tempStr+a;
int count=0;
for(int j=0;j<length;j++)
{
if(a==str.charAt(j))
{
out = out+" At Loc : "+(j+1);
count++;
}
}
System.out.println(" CHar "+a+" No. of times:
= "+count+out);
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is boolean keyword in java?

604


Garbage collection in java?

595


What is meant by design patterns?

587


Why is method overloading not possible by changing the return type in java?

593


What is difference between float and double?

504






What are the advantages of autoboxing?

538


What is string value?

638


What are the differences between abstract class and interface?

513


Why does java not support pointers?

552


What is difference between char array and string?

526


Is java hashset ordered?

576


Explain the difference between string, stringbuffer and stringbuilder in java?

561


Is sizeof a preprocessor?

542


What does I ++ mean?

611


What is a flag and how does it work?

507