Quote (SAJ @ Feb 26 2015 07:38pm)
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.print(“FizzBuzz”);
} else if (i % 3 == 0) {
System.out.print(“Fizz”);
} else if (i % 5 == 0) {
System.out.print(“Buzz”);
} else {
System.out.print(i);
}
}
Does this work?
Go above and beyond with this. You need to WOW them into thinking you're smarter than they are even on this simple project.
i % 3 && i % 5 pretty much mean if it's divisible by 3 and divisible by 5 with no remainder then print fizzbuzz
What else could you do in this situation? Instead of using && there is something more simplistic. This goes beyond the realm of straight programming and shows that you're very logical.
i % 3 && i % 5 is the same thing as i % 15.
A number divisible by 3 and 5 means it must be divisible by the least common multiple. Using this and explaining why you chose this over && will give you a little bit of a leg up on the competition who do it the way you just did it.