BPJ 01-12 Daily B
Background
See the bottom for quick lessons.
Lesson 7
-
Human types ten integers. Compute their sum.
5 10 20 30 40 50 60 70 80 90 or 10 20 30 40 50 60 70 80 90 100
Lesson 7 and 12
- How many lines does the person type until they type DONE on a line by itself? Then print the count.
Lesson 8
- Ask the human for two decimal number, multiply them and trucate the answer into an int variable. Print it.
Lesson 9
- Print a number after each line the person types.
| Person types | You print |
|---|---|
| one | 1 |
| zero | 0 (then quit) |
| nine | 9 |
| NINE | 9 |
| NiNe | 9 |
| (any capitalization of nine) | 9 |
| anything else | -1 |
Lesson 10
- Read a line of text. Use a switch on a char (not String) to keep totals of each group and print at the end.
| Group | Contents |
|---|---|
| special | \ |
| grouping | (){} |
| doc mo room numbers | only 1,0,9 |
| remain | (any other) |
Lesson 11
- Ask human for a start number. Ask for an end number. Print all of the numbers start through end with a “.” after each. If the end is less than start, print a message “Warning: end < start!” If you hit a multiple of 29 in the range, print “EARLY STOP” and stop immediately after printing it.
Lesson 12
-
Use a do-while loop to add up an unknown number of ints, quitting when the input number is 0.
-
As long as the keyboard reader has another word available, read it. Print the total number of words. Note: anything counts as a word: “This @ 5 words.” Nota bene: in Github Codespaces, you will need to hit Control-D to indicate there are no more words.
Quick Background
Chapter 9: if
{
String desc;
if (x < 0) {
desc = "negative ";
} else {
desc = "positive ";
}
desc += Math.abs(x);
}
Chapter 11: for
for(int k=0; k<HOW_MANY; k++) {
System.out.println(k);
}
Chapter 12: while
{
int n = (int)(10*Math.random());
String out = "";
while (n>0) {
out += ".";
n--;
}
System.out.println(out);
}