Hey guise, I’m looking for some feedback on what y’all think of my solution I came up with on the FizzBuzz exercise. I had to google how to code the divisible part of the code, but once I got that I found a solution.
I didn’t watch his solution until after I came up with mine. He says in his solution part of his code was “redundant” or something, I think my code just happens to cancel that out by using boolean variables, where I later translate the true/false into a String by reading the users int value. I think I got lucky figuring this out actually haha
code below. Let me know what ya’ll think
Scanner scanner = new Scanner(System.in);
System.out.print("Number: ");
int userInput;
userInput = scanner.nextInt();
boolean FizzBuzz = userInput % 5 == 0 & userInput % 3 == 0;
boolean Fizz = userInput % 5 == 0;
boolean Buzz = userInput % 3 == 0;
if (FizzBuzz){
System.out.println("FizzBuzz");
} else if (Fizz){
System.out.println("Fizz");
} else if (Buzz) {
System.out.println("Buzz");
} else
System.out.println(userInput);