Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
public class FizzBuzz {

public void printNumbers(){
String s = "";
for(Integer i=1; i<=100; i++){
if(isDivisibleBy3(i)){
s += "Fizz ";
}else if(isDivisibleBy5(i)){
s += "Buzz ";
}else if(isDivisibleBy3And5(i)){
s += "FizzBuzz ";
}else if(isDivisibleBy7(i)){
s += "Rizz ";
}else if(isDivisibleBy11(i)){
s += "Jazz ";
}else{
s += i.toString() + " ";
}
}
System.out.println(s);
}

public boolean isDivisibleBy3(int number){
return number % 3 == 0;
}

public boolean isDivisibleBy5(int number){
return number % 5 == 0;
}

public boolean isDivisibleBy3And5(int number){
return number % 3 == 0 && number % 5 == 0;
}

public boolean isDivisibleBy7(int number){
return number % 7 == 0;
}

public boolean isDivisibleBy11(int number){
return number % 11 == 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class TestFizzBuzz {
public static void main(String[] args) {
FizzBuzz b = new FizzBuzz();
b.printNumbers();
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
public class FooBarQix {

public String compute(int number){
String s = "";
if(number % 3 == 0){
s += "Foo";
}
if(number % 5 == 0){
s += "Bar";
}
if(number % 7 == 0){
s += "Qix";
}

char[] digits = String.valueOf(number).toCharArray();
for(int digit : digits){
if(digit == '3') {
s += "Foo";
}
if(digit == '5') {
s += "Bar";
}
if(digit == '7') {
s += "Qix";
}
}
if(s.isEmpty()){
s = "" + number;
}
return s;
}

public String compute2(int number){
String s = "";
boolean isDivisible = false;
if(number % 3 == 0){
s += "Foo";
isDivisible = true;
}
if(number % 5 == 0){
s += "Bar";
isDivisible = true;
}
if(number % 7 == 0){
s += "Qix";
isDivisible = true;
}

char[] digits = String.valueOf(number).toCharArray();
for(char digit : digits){
if(digit == '3') {
s += "Foo";
}
else if(digit == '5') {
s += "Bar";
}
else if(digit == '7') {
s += "Qix";
}
else if(digit == '0'){
s += "*";
}
else if(!isDivisible){
s += digit;
}
}
return s;
}

public void printNumbers(){
for(int i=1; i<=101; i++){
//System.out.println(i + " => " + this.compute(i));
System.out.println(i + " => " + this.compute2(i));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class TestFooBarQix {
public static void main(String[] args) {
FooBarQix b = new FooBarQix();
b.printNumbers();
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class PairsOf2 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class TestPairsOf2 {
public static void main(String[] args) {
}
}