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
Is void a type?
What are the different approaches to implement a function to generate a random number?
How hashmap works in java?
What is byte code and why is it important to java’s use for internet programming?
What is the difference between JVM and JRE?
'A class is a template for an object' explain this statement.
What is methodological framework?
Can a java program have 2 main methods?
What is the purpose of garbage collection in java, and when is it used?
Give few difference between constructor and method?
What is static and final keyword in java?
Which category the java thread do fall in?
What are the differences between stringbuffer and stringbuilder?
How does linkedhashmap work in java?
What is the console in java?