CodingBat: Java. Update 2013.1


For further help with Coding Bat (Java), please check out my books. I am also available for tutoring.


As I thought I was done with publishing my solutions to the entire Coding Bat: Java library of exercises, with a total of over 200, Nick Parlante updated his website and added some more exercises. Apparently, his aim was to thoroughly prepare students for “FizzBuzz” interview questions.

The first exercise was added to Warmup-1, the others to Logic-1.

All solutions were successfully tested on 28 March 2013.

or35:

public boolean or35(int n) {
	return n % 3 == 0 || n % 5 == 0;
}

more20:

public boolean more20(int n) {
	return n % 20 == 1 || n % 20 == 2;
}

old35:

public boolean old35(int n) {
	return n % 3 == 0 ^ n % 5 == 0;
}

specialEleven:

public boolean specialEleven(int n) {
	return n % 11 == 0 || n % 11 == 1;
}

less20:

public boolean less20(int n) {
	return (n + 1) % 20 == 0 || (n + 2) % 20 == 0;
}

fizzString:

public String fizzString(String str) {
	boolean fizz = str.charAt(0) == 'f';
	boolean buzz = str.charAt(str.length() - 1) == 'b';

	if (fizz && buzz) return "FizzBuzz";
	if (fizz) return "Fizz";
	if (buzz) return "Buzz";
	return str;
}

fizzString2:

public String fizzString2(int n) {
	boolean fizz = n % 3 == 0;
	boolean buzz = n % 5 == 0;

	if (fizz && buzz) return "FizzBuzz!";
	if (fizz) return "Fizz!";
	if (buzz) return "Buzz!";
	return n + "!";
}

For further help with Coding Bat (Java), please check out my books. I am also available for tutoring.


2 thoughts on “CodingBat: Java. Update 2013.1

  1. Ronnie

    For “less20” my code reads as:

    public boolean less20(int n) {
    if (n%40 == 18 || n%40 == 19) return true;
    else return false;
    }

    Which returns all the tests as OK except for the “other tests”. What am I not accounting for in my solution?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Spammer prevention; the answer is an integer: * Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.