fizzbuzz.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // ****************************************************
  2. // Programmer: Jonathan Landrum
  3. // Date: 29 October 2011
  4. // Class: Comp. Sci. 101 (Seriously)
  5. // ****************************************************
  6. // Program: fizzBuzz.java
  7. // Purpose: To prove that I can program.
  8. // Assumptions: A lot, apparently.
  9. // ****************************************************
  10. import java.util.Scanner;
  11. public class fizzBuzz {
  12. public static void main (String[] args) {
  13. // --------------------------------------------
  14. // Variables
  15. // --------------------------------------------
  16. int c = 1;
  17. String response;
  18. Scanner scan = new Scanner(System.in);
  19. // --------------------------------------------
  20. // Introduce the program
  21. // --------------------------------------------
  22. System.out.println ("-------------------------------------");
  23. System.out.println ("- Fizz Buzz -");
  24. System.out.println ("-------------------------------------");
  25. System.out.println ();
  26. System.out.println ("This program reproduces a traditional");
  27. System.out.println ("British children's counting game, but");
  28. System.out.println ("more specifically, it represents a");
  29. System.out.println ("coding challenge.");
  30. System.out.println ();
  31. System.out.print ("Would you like to continue? [Y/N] ");
  32. response = scan.nextLine();
  33. // --------------------------------------------
  34. // Main block
  35. // --------------------------------------------
  36. while (response.charAt(0) == 'y' || response.charAt(0) == 'Y') {
  37. while (c <= 100) {
  38. if (c > 3) {
  39. if (c % 3 == 0 && c % 5 == 0) {
  40. System.out.println ("FizzBuzz");
  41. } else if (c % 3 == 0 && c % 5 == 1) {
  42. System.out.println ("Fizz");
  43. } else if (c % 3 == 1 && c % 5 == 0) {
  44. System.out.println ("Buzz");
  45. } else {
  46. System.out.println (c);
  47. } // End test if block
  48. } else {
  49. System.out.println (c);
  50. } // End print if block
  51. c++;
  52. } // End main while block
  53. System.out.println ("-------------------------------------");
  54. System.out.println ("Process complete.");
  55. System.out.print ("Would you like to continue? [Y/N] ");
  56. response = scan.nextLine();
  57. } // End while
  58. System.out.println ();
  59. System.out.println ("\\\\//_ Live long and prosper.");
  60. } // End main
  61. } // End fizzBuzz