Learning Java, Help Please
Hi guys,
I am learning Java, but I am stuck at the beginning making Fizz Buzz. My teacher suggested that we try it on our own and I am stuck.
"Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."
If I could get some help I would really appreciate it.
XOXOXO
Megan
Re: Learning Java, Help Please
Let's say you can write a progran that prints the integers between 1 and 100.
Now to check whether an integer i is a multiple if 3 you can use the modulo operator % like,
if (i%3 == 0) {
// Fizz
}
You can check for multiples of 5 analogously. And to check whether both 3 and 5 multiplicity apply you can combine the tests for each using the and operator &&.
Re: Learning Java, Help Please