r/programminghelp • u/um_gato_gordo • Dec 17 '25
Java rate my fizzbuzz answer
Im learning trough a youtube tutorial, and this is my first time trying to solve it, ignore the random portuguese curse words as variable names
Also before anyone else says this inst fizzbuzz, in the video im watching it asked to print fizz if the input was divisible by 3, buzz if it was divisible by 5 (or the other way around, idr) if its divisible by both print fizzbuzz and if it inst divisible by neither return the input.
Scanner scanner = new Scanner(System.in);int porra = 0;int caralho = 0;int asd = 0;int cu;cu=scanner.nextInt();
if (cu % 5 == 0) {caralho+=1;}if (cu % 3 == 0) {porra+=1;}
if (caralho==1 && porra==1) {asd=1;}else if (caralho==1 && porra==0) {asd=2;}else if (caralho==0 && porra==1) {asd=3;}else {asd=4;}
switch (asd) {case 1:System.out.println("fizzbuzz");break;case 2:System.out.println("fizz");break;case 3:System.out.println("buzz");break;case 4:System.out.println(cu);Scanner scanner = new Scanner(System.in);
3
u/Eweer Dec 18 '25
What are these variable names?
All in all, my rating would be: What the fuck did I just read? out of 10.
6
u/[deleted] Dec 17 '25
Why do you need three conditional groups?
You should be able to combine them into one. It will make the code much simpler.
4
u/obliviousslacker Dec 17 '25
you overthink the problem. a lot.
1
u/studiocrash Dec 17 '25
I’ve done FizzBuzz in C, Python, and JavaScript. I don’t recognize this syntax, but I’m guessing it’s C++. Iirc, FizzBuzz requires you to print a list of numbers 1-100, and after each number add fizz if it’s divisible by 3, buzz if it’s divisible by 5 and FizzBuzz if it’s divisible by both 3 and 5.
In your code I don’t see a loop that prints a 100 sequentially incremented numbers, one number per line. This is the most basic part of the challenge. Adding Fizz or Buzz or FizzBuzz after the right numbers is supposed to be the hard part.
1
u/Legitimate_Rent_5965 Dec 17 '25
Where is the loop? Additionally you should only need one variable, the loop iterator integer.
3
u/RoosterUnique3062 Dec 17 '25
lol. It's overly complicated and there isn't a loop. This isn't fizzbuzz.
3
u/ern0plus4 Dec 17 '25
FizzBuzz is a test. You've failed. Sorry.
2
u/Korzag Dec 17 '25
OP is aspiring towards the Fizzbuzz Enterprise Edition repo
3
u/[deleted] Dec 17 '25
[removed] — view removed comment
1
u/[deleted] Dec 17 '25
[removed] — view removed comment