Fizz Buzz Comments
Comments
-
My code works fine! Admin, thanks you for explanation part after the task, picked up something new!
-
For ruby learners, there is a fizzbuzz problem on rubeque. You can learn a lot from it.
[Delete if inappropriate] -
Not checked off as well
-
@Davin, did it get checked off when you went to the next page?
-
'import java.util.*;
public class Main{
public static void main(String[] args) { for (int i=0; i<=100; i = i+1){
boolean one = i%3==0; boolean two = i%5==0; boolean three = (i%5==0)&&(i%3==0); if (three=true){ System.out.println("FizzBuzz"); } else if(one=true){ System.out.println("Fizz"); } else if(two=true){ System.out.println("Buzz"); } else { System.out.println(i); } } //your code here }
}'
For wathever reason its just printing FizzBuzz...help?
-
I did mine a different way does it mean my code isn't as efficient or wrote very well?
-
There are many ways to solve this problem. Run-time efficiency doesn't matter for such small problems, but it's important to try to write clear code. See the featured answers for another possible solution.
-
my solution:
for(int i=1;i<=100;i++){String a=i%5==0?"Buzz":""; String b=i%3==0?"Fizz":""; System.out.println(b.length()+a.length()!=0?b+a:i); }
-
for(int i=1;i<=100;i++){
String a=i%5==0?"Buzz":""; String b=i%3==0?"Fizz":""; System.out.println(b.length()+a.length()!=0?b+a:i); }
-
My stupid
else if((i%3 ==0) && (i%5==0)){
System.out.println("FizzBuzz");
}doesn't seem to give FizzBuzz for 15! Why? GRRR
-
@catypus
the order of IF statement is important, if the printIn for 3 has already happened it wont overwrite with 3 & 5 printIn, try making that statement before the 3 and 5 individually.
Matt
Nov 18, 1:25 AMCompleted successfully, not checked off on the side list, though.