0

guys help me out

Let's say you were asked the following question: 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". You would type your solution into the textbox and hit Submit when you're happy with it. You and your interviewer would then see something like this: """ x mod 3 = Fizz x mod 5 = Buzz x mod 15 = FizzBuzz else print x """ for x in range(1,101): if x % 15 == 0: print "FizzBuzz" # Catch multiples of both first. elif x % 3 == 0: print "Fizz" elif x % 5 == 0: print "Buzz" else: print x

20th Oct 2017, 7:04 PM
Walter Mugo
Walter Mugo - avatar
3 Respuestas
0
""" x mod 3 = Fizz x mod 5 = Buzz x mod 15 = FizzBuzz else print x """ for x in range(1,101): if x % 15 == 0: print ("FizzBuzz") elif x % 3 == 0: print ("Fizz" ) elif x % 5 == 0: print ("Buzz" ) else: print (x)
20th Oct 2017, 7:16 PM
Shaikh Mehboob Siraj
Shaikh Mehboob Siraj - avatar
0
public class Program { public static void main(String[] args) { for (int x = 1; x <= 100; x++) if (x%15 == 0) System.out.println("FizzBuzz"); else if (x%3 == 0) System.out.println("Fizz"); else if (x%5 == 0) System.out.println("Buzz"); else System.out.println(x); } }
20th Oct 2017, 7:24 PM
John Wells
John Wells - avatar
0
thanks
23rd Oct 2017, 11:02 AM
Walter Mugo
Walter Mugo - avatar