-
August 4th, 2011, 11:45 PM
#1
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
-
August 5th, 2011, 12:43 AM
#2
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 &&.
Last edited by nuzzle; August 5th, 2011 at 12:55 AM.
-
August 5th, 2011, 08:36 PM
#3
Re: Learning Java, Help Please
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
|
Click Here to Expand Forum to Full Width
|