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 / kishore nerella

class Wordcount
{
public static void main(String[] args)
{

String s="hello world";

for(int i=0;i<s.length();i++)
{
String s1=""+i;

int count=1;
if(s.charAt(i)!=' ')
{

for(int j=i+1;j<s.length();j++)
{
if(s.charAt(i)==s.charAt(j))
{
count++;
s1=s1+"&"+j;
}
}
int before=0;
for(int x=i-1;x>0;x--)
{
if(s.charAt(i)==s.charAt(x))
before=1;
}
if(before==0)
System.out.println("the occurence of letter "+s.charAt(i)+" no of times= "+count+"--- positions="+s1);
}

}

}
}

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you control extraneous variables?

857


Can we write a class without main method in java?

896


How do you start a new line in java?

923


What is the epoch date?

951


Are primitives objects?

1001


Describe what a thread-local variable is in java?

960


How will you add panel to a frame?

1047


What are the four pillars of java?

1157


design an lru cache in java?

937


What is a instance variable in java?

985


What are 5 boolean operators?

1099


What is local variable and instance variable?

999


Is c better than java?

906


What is javac used for?

887


Which types of exceptions are caught at compile time?

973