Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. 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.
  2. int x = 1;
  3.  
  4. for (i = 0; i < 100; i++) {
  5. if ( x%5 = 0 && x%3 != 0) {
  6. system.out.println("fizz");
  7. }
  8. else if ( x%3 = 0 && x%5 != 0) {
  9. system.out.println("buzz");
  10. }
  11. else if ( x%3 = 0 && x%5 = 0) {
  12. system.out.println("fizzbuzz");
  13. }
  14. else {
  15. system.out.println(x);
  16. }
  17. x++;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement