Skip to content

Java打印Fizzbuzz #54

Description

@strongant
/** * Created by strongant on 2017/5/25. */publicclassFizbuzz {
publicstaticvoidmain(String[] args) {
intnum = 100;
printFizzbuzz(num);
}
privatestaticvoidprintFizzbuzz(intnum) {
for(inti = 1; i <= num; i++) { // count from 1 to 100if (((i % 5) == 0) && ((i % 7) == 0)) // A multiple of both?System.out.print("fizzbuzz");
elseif ((i % 5) == 0) System.out.print("fizz"); // else a multiple of 5?elseif ((i % 7) == 0) System.out.print("buzz"); // else a multiple of 7?elseSystem.out.print(i); // else just print itSystem.out.print(" ");
}
System.out.println();
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions