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
What is the use of parse function in java?
What is type parameter in java?
Can we sort array in java?
What are the methods used to implement for the key object in the hash map?
What is the purpose of the main method?
What is meant by javabeans?
How would you use Bubble Sort to sort the number of elements?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
Define an enumeration?
What does yield method of the thread class do?
what is the swingutilities.invokelater(runnable) method for? : Java thread
How can you add and remove nodes in jtree?
What is the purpose of the runtime class in java programming?
What is callablestatement? How you can call stored procedure to pass in parameter?
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?