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 a numeric format?

554


Explain 5 features introduced in jdk 1.7?

603


What do you mean by access modifier?

550


What is the use of accept () method in java?

602


Why do we need autoboxing in java?

510






What are the 4 versions of java?

551


What is the this keyword?

549


How do constructors use this() and super()?

537


How is java created?

530


Can a list be null in java?

533


What is empty list in java?

613


What is immutable state?

498


What is the purpose of using bufferedinputstream and bufferedoutputstream classes?

544


What is a modifier?

855


What are white spaces in java?

520