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 / meet parikh

Here you go,

public class Hello {
static String s = "";
static String word = "Hello World";
public static void main(String[] args){
for(int i=0; i<word.length();i++){
char tchar = word.charAt(i);
if(!checkCharContains(tchar)){
int count = 0;
StringBuilder sb = new StringBuilder();
for(int j=0;j<word.length();j++){
char ttchar = word.charAt(j);
if(ttchar == tchar){
count++;
sb.append(j).append(",");
}
}
sb.deleteCharAt(sb.length()-1);
s += tchar + " : " + sb.toString() + " & " +
count + " \n";
}
}
System.out.println(s);
}
public static boolean checkCharContains(char t){
boolean result = false;
for(int i=0;i<s.length();i++){
if(s.charAt(i) == t){
result = true;
}
}
return result;
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to convert string to char and vice versa?

515


What is the use of pattern in java?

511


Write a program in java to find the maximum and minimum value node from a circular linked list.

525


What is the use of generics? When was it added to the Java development Kit?

555


What is a pattern what is an anti pattern?

510






What is the use of StringTokenizer class?

611


What is static block?

590


What is thread synchronization in java?

484


How to find the largest value from the given array.

526


What is a boolean output?

524


What is JFC?

708


Can private members of a base class are inheritable justify?

488


How does regex work?

526


How do you write a scanner class in java?

568


What is the static keyword?

592