GIVE ME MY FIZZBUZZ
void fizzbuzz() {
for(int i=1;;i++) {
String s = i%3==0?"fizz":"";
s += i%5!=0?"":"buzz";
System.out.println(s.isEmpty()?i:s);
}
}
perl -e 'say"Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'
#!/usr/bin/env xcrun swift -I
print((1...100).map{ $0 % 3 == 0 ? $0 % 5 == 0 ? "FizzBuzz" : "Fizz" : $0 % 5 == 0 ? "Buzz" : "\($0)"})
what's the point of these threads? there's no challenge whatsoever in writing fizzbuzz.
>>58114873
Yeah, it's the most basic of programming tasks. But who gives a shit.
python2for x in range(100): print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1
>>58114873
newfag
for(i=1;i<=100;i++){
i=i.toString();
var tmp = i.split('');
if(tmp[tmp.length-1] == 5){
if(tmp[tmp.length-1] == 3)
{
console.log("FizzBuzz!")
}
else{
console.log("Buzz!");
}
}
else if(tmp[tmp.length-1] == 3){
console.log("Fizz!");
}
else{
console.log(i);
}
}
graduated a bit ago but only starting to apply to some jobs now so am doing these excersizes for practice
any pointers would be appreciated
>>58117354
int *ptr
>>58117388
What?
I'm using javascript
>>58117452
Then I am afraid pointers will be of no use to you.
using namespace std;
int main() {
int i;
i = (5/5) - 1;
i *= 0;
cin >> i;
i = 0;
for(int i = 0; i < 25; i++){
if(i == 15)
cout << "Fizzbuzz"; // This prints Fizzbuzz, since 15 is divisible by both 5 and 3 ;3
else if(i == 5 || 10 || 15 || 20 || 25)
cout << "Buzz"; // This prints only Buzz, as these numbers are only divisible by 5 ;)
else if(i == 3 || 6 || 9 || 12 || 15 || 18 || 21 || 24)
cout << "Fizz"; //This prints Fizz, as these numbers are only divisible by 3 :)
}
>>58117354
Here's a pointer: don't use that font, please.
Fixd for you btw
for(i=1;i<100;i++) {
var tmp = i%3==0?'fizz':'';
tmp += i%5!=0?'':'buzz';
console.log(tmp.length==0?i:tmp);
}
>>58114846
fugg thats hot
>>58117354
>>58118076
Alternative because I was bored
for(i=1;i<100;i++) {
var tmp = '';
switch(true) {
case(i%3==0):
tmp += 'fizz';
case(i%5==0):
tmp += i%5==0?'buzz':'';
break;
}
console.log(tmp.length==0?i:tmp);
}
>>58117354
>>58118076
>>58118219
I'm bored. Now I'm going to bed. Here's what I could come up with for you.
for(i=1;i<100;i++) {
console.log((i%3?'':'fizz')+(i%5?'':'buzz')||i);
}
>>58114433
>not providing glorious hex magic value solutionfunction fizzbuzz(n) {
let m = [null, "Fizz", "Buzz", "FizzBuzz"];
let v = 0x30490610;
for (let i = 1; i <= n; i++) {
console.log(m[v & 3] || i);
v = (v >> 2) | (v & 3) << 0x1c;
}
}
>>58114433package fb;
class FizzBuzz {
private static final FIZZ = "fizz";
private static final BUZZ = "buzz";
private int n;
public FizzBuzz(int n) {
this.n = n;
}
public void run() {
for (int i=0; i<n+1; i++) {
if (i%3==0 && i%5==0) {
System.out.println(FIZZ+BUZZ);
} else if (i%3==0) {
System.out.prinln(FIZZ);
} else if (i%5==0) {
System.out.prinln(BUZZ);
} else {
System.out.prinln(Integer.toString(i));
}
}
}
public static void main(String[] args) {
FizzBuzz fizzBuzz = new FizzBuzz(100);
fizzBuzz.run();
}
}
>>58118996
Forgot the type on the constants. Should be this instead:package fb;
class FizzBuzz {
private static final String FIZZ = "fizz";
private static final String BUZZ = "buzz";
private int n;
public FizzBuzz(int n) {
this.n = n;
}
public void run() {
for (int i=0; i<n+1; i++) {
if (i%3==0 && i%5==0) {
System.out.println(FIZZ+BUZZ);
} else if (i%3==0) {
System.out.prinln(FIZZ);
} else if (i%5==0) {
System.out.prinln(BUZZ);
} else {
System.out.prinln(Integer.toString(i));
}
}
}
public static void main(String[] args) {
FizzBuzz fizzBuzz = new FizzBuzz(100);
fizzBuzz.run();
}
}
I hate that mine is too long for these threads http://pastebin.com/raw/WjbiGNEC
for (int i = 1; i < 100; i++) {
String str = "";
if (i % 3 == 0) {
str += "Fizz";
}
if (i % 5 == 0) {
str += "Buzz";
}
if (str.equals("")) {
str = i + "";
}
System.out.println(str);
}