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 the use of isempty in java?
What is final method in java?
How do you input a string in java?
When is the garbage collection used in Java?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
In java how do we copy objects?
What is set in java?
What class allows you to read objects directly from a stream in java programming?
Give few difference between constructor and method?
In the below example, how many string objects are created?
Write a program in java to establish a connection between client and server?
What do you mean by platform independence?
Which is best ide for java?
Give any two differences between C++ and java.
What is the final field modifier?