Looping and outputting strings

Here is what I need.  I need a counter that goes from 1-100 that list each number.  If a number is divisible by 3, then write "divisible by 3" as opposed to the number.  If a number is divisible by 5 then write "divisible by 5" as opposed to the number, if the number is divisible by 3 and 5 then write, "divisible by 3 and 5" as opposed to the number.  If the number is not divisible by 3 or 5 or 3 and 5 then just write the number.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StringBuilder sb = new StringBuilder();
for(int i=1;i<=100;i++)
   bool divBy3 = (i%3) == 0;
   bool divBy5 = (i%5) == 0;
   if(divBy3 && divBy5)
      sb.AppendLine(string.Format("{0} divisible by 3 and 5", i));
   else if(divBy3)
      sb.AppendLine(string.Format("{0} divisible by 3", i));
   else if(divBy5)
      sb.AppendLine(string.Format("{0} divisible by 5", i));


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Daniel Van Der WerkenIndependent ConsultantCommented:
Is this homework?  I think we're not supposed to do homework for people.

What approach have you taken so far?

I would see something like this:

for( int i = 1; i <= 100; i++ )
   if ( i % 3 )
      if ( i % 5 )

That should get you started....
NavneetSoftware EngineerCommented:

Better you start writing code, then raise a  question. if required. (I bet you won't require any help :) )
But still we are always here to help.

VBBRettAuthor Commented:
Nope, it's not homework at all.  It just so happens I wrote code earlier and wanted to make sure we were all on the same page.  It just so happens that we are, thanks anyways guys!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.