Am 27.11.2010 15:48, schrieb Norman Dunbar:
On 26/11/10 21:48, Tobias Fröschle wrote:

main(){for(;;i++){puts(!i%3)?"FIZZ":(!(i%5)?"BUZZ":""));}}
Error!
Warning!
Puts() needs #include<stdio.h>  or at least defining correctly!
It should, for the sake of art, but doesn't need to.
Main() always returns int.
Main always takes two parameters int and char **.
It should, to generate anything maintainable, but doesn't need to. C allows you to ignore return values.
Your main() function doesn't return a value.

The correct (?) version would then be something like:

#include<stdio.h>
int main(int argc, char
**argv){for(;;i++){puts(!i%3)?"FIZZ":(!(i%5)?"BUZZ":""));}return 0;}

And is of course way more readable, structured, object-oriented and
modern as well.....

I can do even better (alas, not on the QL - And: I'll probably never get employment as a Java programmer):

/*
 * FuzzBuzz.java
 */
package fuzzbuzz;

/**
 *
 * @author tofro
 */
public class Main {
    public class Fuzzer {
        int divisor;
        String infoStr;
        public Fuzzer(String info, int _divisor){
            infoStr = info;
            divisor = _divisor;
        }
        public void test (int i){
            if ((i % divisor) == 0){
                System.out.println(i + infoStr);
            }
        }
    }

    private Fuzzer fArray [] = new Fuzzer[2];

    Main(){
        fArray[0] = new Fuzzer("FUZZ", 3);
        fArray[1] = new Fuzzer("BUZZ", 5);
    }

    public void test (int i){
        for (int j = 0; j < fArray.length;j++){
            fArray[j].test(i);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Main m = new Main();
        for (int i = 0; i < 100 ;i++){
            m.test(i);
        }

    }
}

_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to