The problem I’m trying to solve is composing a paragraph and when I say 1 my program says thumb on the second line of my song. When my program says 2 it should say shoe on my second line of my song. My program is not working as I planned and I’m not sure if I’m using the switch statement correctly inside the for loop or if the sequence of my program is wrong.
import acm.program.*;
public class SingChildSong extends ConsoleProgram {
public void run() {
for (int i = 1; i < 3; i++){
println ("This old man, he played" + i);
switch (i) {
case 1: println("thumb"); break;
case 2: println("shoe"); break;
case 3: println("knee"); break;
}
println ("He played knick-knack on my" + (i));
println ("With a knick-knack, paddy-whack");
println ("Give your dog a bone.");
println ("This old man came rolling home.");
println ( "" );
}
}
}
If I get it right you are intending to do:
As you say Strings are not yet studied in your book, the correct answer, without Strings should be: