Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.seamfix.onboarding;
- import java.util.Scanner;
- public class AppBioseNonso {
- static Scanner scanner = new Scanner(System.in);
- public static void main(String[] args) {
- System.out.println("Please input a number to check if multiples of 3&5, 3 or 5");
- String input = scanner.nextLine();
- getFizzBuzzValue(input);
- }
- /**
- * Method that checks if input value is either a multiple of 3&5, 3 or 5
- * It prints FizzBuzz if input is multiple of 3 & 5 and return the input,
- * if input is not a multiple of 3 & 5, 3 or 5)
- *
- * @param multiple (The input value to check)
- */
- public static void getFizzBuzzValue(String multiple) {
- int input = 0;
- try {
- input = Integer.parseInt(multiple); // Throws NumberFormatException
- if ((input % 3 == 0) && (input % 5 == 0)) {
- System.out.println("FizzBuzz");
- } else if (input % 3 == 0) {
- System.out.println("Fizz");
- } else if (input % 5 == 0) {
- System.out.println("Buzz");
- } else {
- System.out.println(input);
- }
- } catch (NumberFormatException ex) {
- System.out.println("Please enter a valid number");
- String anotherInput = scanner.nextLine();
- getFizzBuzzValue(anotherInput);
- }
- }
- }
Add Comment
Please, Sign In to add comment