Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 function overriding and overloading in java?

1047


What is nested loop? What is dangling else condition in it?

1021


What does system.gc() and runtime.gc() methods do?

989


What is immutable class in java?

889


Explain Basics of OOP Language in java

985


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

935


What is bom encoding?

945


What is byte code and why is it important to java’s use for internet programming?

1045


What’s a deadlock?

1044


What is length in java?

948


What java ide should I use?

931


What is ++ a in java?

921


I want to re-reach and use an object once it has been garbage collected. How it's possible?

952


What is a qms manual?

933


Is cout buffered?

1108