Please help me, IndexOf problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Please help me, IndexOf problem

  1. #1
    Join Date
    Nov 2004
    Posts
    32

    Please help me, IndexOf problem

    Hi, I am having big problems using IndexOf. I am trying to create a table of numbers from 1-100 and every time a 5 appears change the word to fiz.

    I can do this using multiples of 5 but not when a 5 appears, for example 51 needs to be changed to "fiz"

    any help would be greatfully appreciated.



    class cw1d
    {
    public static void main (String[] args)
    {
    System.out.println("|-----------------------------------------------");
    System.out.println("| FizBuz Simulator");
    System.out.println("| by ");
    System.out.println("|-----------------------------------------------");

    int counter;
    String number="0";


    for (counter=1; counter<=100; counter++)

    {
    if (counter%5==0 && counter%7==0)

    {
    System.out.print("fizbuz\t");
    }

    number=number.indexOf(counter);

    // if (counter%5==0)
    // {
    // System.out.println("fiz");
    // }
    // else


    if (number.indexOf=="5" || counter%5==0)

    {
    System.out.print("fiz\t");
    }


    else

    {
    System.out.println(counter);
    }


    if (counter%7==0)

    {
    System.out.print("buz\t");
    }


    else


    {
    System.out.print(counter);
    System.out.print("\t");

    }



    }
    }


    }

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    turn the number into a string then search for "5" in that string.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center