-
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");
}
}
}
}
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks