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

What is the use of parse function in java?

505


What is type parameter in java?

510


Can we sort array in java?

521


What are the methods used to implement for the key object in the hash map?

559


What is the purpose of the main method?

536






What is meant by javabeans?

607


How would you use Bubble Sort to sort the number of elements?

574


How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?

596


Define an enumeration?

607


What does yield method of the thread class do?

572


what is the swingutilities.invokelater(runnable) method for? : Java thread

539


How can you add and remove nodes in jtree?

607


What is the purpose of the runtime class in java programming?

553


What is callablestatement? How you can call stored procedure to pass in parameter?

540


FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?

2624