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
What is methodological framework?
Why is java so popular?
Which class represents the socket that both the client and server use to communicate with each other?
What interface is extended by awt event listeners?
What is the size of int?
What is the difference between equals() and == in java?
What is percentage in java?
What is empty string literal in java?
How does thread synchronization occurs inside a monitor?
What is the purpose of using java.lang.class class?
What is the difference between int and integer in java?
Why do we use predicate in java?
Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.
Does apple use java?
What is the use of http-tunneling in rmi?