Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package com.seamfix.onboarding;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AppBioseNonso {
  6. static Scanner scanner = new Scanner(System.in);
  7.  
  8. public static void main(String[] args) {
  9.  
  10. System.out.println("Please input a number to check if multiples of 3&5, 3 or 5");
  11. String input = scanner.nextLine();
  12. getFizzBuzzValue(input);
  13. }
  14.  
  15. /**
  16. * Method that checks if input value is either a multiple of 3&5, 3 or 5
  17. * It prints FizzBuzz if input is multiple of 3 & 5 and return the input,
  18. * if input is not a multiple of 3 & 5, 3 or 5)
  19. *
  20. * @param multiple (The input value to check)
  21. */
  22. public static void getFizzBuzzValue(String multiple) {
  23. int input = 0;
  24. try {
  25. input = Integer.parseInt(multiple); // Throws NumberFormatException
  26. if ((input % 3 == 0) && (input % 5 == 0)) {
  27. System.out.println("FizzBuzz");
  28. } else if (input % 3 == 0) {
  29. System.out.println("Fizz");
  30. } else if (input % 5 == 0) {
  31. System.out.println("Buzz");
  32. } else {
  33. System.out.println(input);
  34. }
  35. } catch (NumberFormatException ex) {
  36. System.out.println("Please enter a valid number");
  37. String anotherInput = scanner.nextLine();
  38. getFizzBuzzValue(anotherInput);
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment