Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This example is from _Java Examples in a Nutshell_. (http://www.oreilly.com)
- // Copyright (c) 1997 by David Flanagan
- // Slight Editing by Piffy.
- package fizzbuzz;
- /**
- *
- * @author piffy2
- */
- public class FizzBuzz {
- public static String FizzBuzz(int x) {
- if (((x % 5) == 0) && ((x % 7) == 0))
- return "fizzbuzz";
- else if ((x % 5) == 0)
- return "fizz";
- else if ((x % 7) == 0)
- return "buzz";
- return ""+x;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[ ] args) {
- for(int i = 1; i <= 100; i++) {
- System.out.print(FizzBuzz(i));
- System.out.print(" ");
- }
- System.out.println( );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement