Posted: Wednesday, September 23.
JavaBat is a Web site allowing you to practice Java: After reading a relatively short problem and writing a solution, you can submit it to JavaBat to test your solution.
JavaBat's questions are posed in terms of writing methods, which is a concept that we haven't seen yet, but it's easy enough to explain. Below is an example of a method that I've written.
public int distanceBetween(int a, int b) {
int diff;
if (a > b) {
diff = a - b;
} else {
diff = b - a;
}
return diff;
}
As seen in the first line, here we are writing a method named
distanceBetween that computes an integer. As
seen in the parentheses, this method has two inputs
(also known as parameters) named a and b.
The method performs some computation and when it has determined its
answer, we use a return statement,
as illustrated above.
JavaBat has many problems, but I've picked out a few and written some others that I think are particularly good practice for now.
| Chapter 4: Using Numbers | |
| 243564 | tensDigit |
| Chapter 5: Repetition | |
| 288582 | factorial |
| 262070 | sumFactors |
| 264885 | mortgage |
| 284814 | pyramidal |
| 165941 | dividesSelf |
| Chapter 7: Conditional execution | |
| 154485 | sumDouble |
| 184004 | nearHundred |
| 286596 | canBeTriangle |
| 172021 | close10 |
| Chapter 8: Strings | |
| 191914 | notString |
| 190570 | missingChar |
| 173784 | stringE |
| 196441 | everyNth |
| 117334 | stringSplosion |
| 131516 | sameEnds |
| Chapter 10: More on classes | |
| 282350 | quadratic |