Is it bad? If yes why?
Is it bad? If yes why?
Hard coding limits
yes, because of the formatting
it's fine
any "optimizations" like % 15 instead of 3 and 5 would just defeat the purpose and demonstrate that you already knew the answer
it's not bad, but also not perfect
Why? Looks cleaner like this I think
fizzbuzz starts at 1, not at 0. you have not implemented the specification correctly.
Yes it is terrible.
It prints:
>Fizz
>3
for 3 and
>FizzBuzz
>Fizz
>Buzz
for 15
>6 fizzbuzzers above can't read code.
>didn't even test his own JS code
"Don't call us, because we won't call you."
Bad logic, bad structure. Even though it's a short program it's annoying to maintain -- too many magic numbers.
That's why the 3 && 5 if is at the top, dude.
it enters to all the ifs if the number is multiple of 15 you dump fuck.
No, it doesn't.
FizzBuzz
Fizz
Buzz
1
2
Fizz
3
4
Buzz
Fizz
6
7
8
Fizz
9
Buzz
11
Fizz
12
13
14
Fizz
Buzz
FizzBuzz
16
no you inbred, its gonna print both. You need elif statements, not just if statements
retard alert: doesn't know difference between if else and an if statement
>elif
Ah, the smell of burned coals in the morning.
also there are mistakes in logic, if the number is multiple of 15 then it will print all FizBuzz, Fizz and Buzz
public void dofizzbuzz() {
for (int i = 0; i < 101; i++) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}
}
you forgot else if
should have used else if on second statements on.
...and as I said before if the number is multiple 3 it will print both Fizz and the number
Change < 101 to
>What style guidelines do you follow
>just fuck my shit up senpai
while(i < max){
var s;
i % 15 ? s = "FizzBuzz" : i % 5 ? s = "Fizz" : i % 3 ? s = "Buzz" : s = i;
Console.log(s);
i++;
}
Am i good at js yet?
>what is 'else' execution order
var s outside of while... ofc... fuck
s = i % 15 ? : ...
would be cleaner also. Would that do any difference though? In efficiency
OP's else only applies to if(i%5 == 0)
public static void doFizzBuzz() {
boolean a, b;
for (int i = 0; i
>that logic
>using Java 7
>in 2014 + 4
use streams!
public static void main(String[] args) {
System.out.println(fizz());
}
public static List fizz() {
return IntStream.range(1, 101).mapToObj(FizzBuzz::getFizzBuzzString).collect(toList());
}
public static String getFizzBuzzString(int i) {
String string = "";
if (i % 3 == 0)
string += "Fizz";
if (i % 5 == 0)
string += "Buzz";
if (string.isEmpty())
return i + "";
return string;
}
program FizzBuzz;
var i:integer;
s:string;
begin
for i:=1 to 100 do
Begin
s:='';
If i mod 3 = 0 then s:=s+'Fizz';
If i mod 5 = 0 then s:=s+'Buzz';
if s='' then writeln(i) else writeln(s);
End;
end.
Do you have a rare bone disease that causes a sharp pain every time you press spacebar? If not, press spacebar more often.
OP's code works on C.
Are ifs in C different?
(defun fb (top)
(loop for x from 1 upto top collect
(let* ((is-five (equal (mod x 5) 0))
(is-three (equal (mod x 3) 0)))
(cond ((and is-five is-three) "fizzbuzz")
(is-five "fizz")
(is-three "buzz")
(t x)))))
(loop for x in (fb 100) do (format t "~A~%" x))
HOW DOES THIS BOARD MANAGE TO HAVE A FIZZBUZZ THREAD EVERYDAY.
ARE YOU GUYS LITERALLY SO RETARDED THAT THIS IS THE EXTENT OF YOUR PROGRAMMING ABILITY.
FUCKING OP IS SO RETARDED. ITS WRONG.
KILL YOURSELF
are you retarded or just baiting?
i hope you're fucking joking you faggot. your shitty code took 86 seconds to execute on a million numbers while took 4 seconds. you're the epitome of "it's new so it must be good." i bet you use Ruby too
Autismus Maximus Mode:
program FizzBuzzNoStringsAttached;
uses crt;
var i:integer;
begin
for i:=1 to 100 do
Begin
If i mod 3 = 0 then Write('Fizz');
If i mod 5 = 0 then Write('Buzz');
if WhereX=1 then writeln(i) else writeln;
End;
end.
you put i++ in if section
of course it works differently
Ah. That's probably because I seldomly use for loops.
Holy fucking shit, which language would allow assignment to your loop variable.
>it's c shitting up everything again...
as expected.
yes, your code works
It's just terrible
>Holy fucking shit, which language would allow assignment to your loop variable.
Any language that has implements "while" loop. This is not the problem there.
Why is Jow Forums so obsessed with fizzbuzz?
As you can see in this thread there Jow Forums has still a lot to learn.
It's supposed to be a Pajeet sieve, the simplest shit to filter out the brainlets
And it is exactly what it is supposed to be
Literally nothing wrong with if and else
Killyourselfes elitists
>not a problem.
Nevermind, I misread that code, it's a while loop and not a for he used, so all is well I presume.
Split out the string conversion from the printing, make a list of rules rather than an iterative process
System.out.println
Here's your problem, you need to print a new line at the end of the loop, not at every print, otherwise it will be:
Fizz
Buzz instead of FizzBuzz
I've seen this guy posting before, he's seriously retarded
Even the most stupid CS dropout can do if, else and prints. Maybe a brainlet will be unnaware of the % operator, but that's it.
It will only filter people with literally 0 programming knowledge, that God knows why would be applying to a job that requires programation.
Main.kt:
val s = StringBuilder()
repeat(100){
s.apply{
a(it % 3, "Fizz")
a(it % 5, "Buzz")
if(isEmpty()) append(it)
}
println(s)
s.setLength(0)
}
Extensions/StringBuilder.kt
fun StringBuilder.a(i: Int, s: String) = if(i==0) append(s) else Unit
As you can see from Jow Forums fizzbuzz threads, there are many God-fearing, God-loving brainlets who have problems with such a simple challenge.
unironically filters out half of Jow Forums
At least someone else in the thread mentioned it but you use three straight up if statements and then an else statement.
The else statement will run EVERY time i%5 != 0, and the second and third if statements will run even when the first statement runs.
It's shit mate.
(define (checkmod a b)
(= (remainder a b) 0))
(define (fizzbuzz x cnt)
(if (
it's fine, you're demonstrating pragmatism by solving the problem in the most direct and time-efficient (programmer time) manner. if the interviewer autist press you about optimization, remind her that you're writing in java
the fizzbuzz in the OP is perfectly cromulant
>baiting this bad