Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write code using any language (even pseudo code) that prints numbers from 1 to 100, but if the number is divisible by 5, print fizz. if it is divisible by 3, print buzz. if it is divisible by both 5 and 3, print fizzbuzz.
- int x = 1;
- for (i = 0; i < 100; i++) {
- if ( x%5 = 0 && x%3 != 0) {
- system.out.println("fizz");
- }
- else if ( x%3 = 0 && x%5 != 0) {
- system.out.println("buzz");
- }
- else if ( x%3 = 0 && x%5 = 0) {
- system.out.println("fizzbuzz");
- }
- else {
- system.out.println(x);
- }
- x++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement