Learn Programming in Java

Seaman Startup

<<Previous | ToC | Next >>

Vivian Killian provided the basic structure of this program, and we are refining her English. Her first line was:

1. Pick a word
We already know that the computer does not pick a word, the (first) human player does that, and the computer can only:
Input word
Are you just going to throw that at the user, with no advance warning, no idea what's going on? Of course not! You already know better than that, right? Maybe you already did The Right Thing: Great!

Vivian's second line has the computer print out a line of dashes, one for each letter of the word that came in. How many dashes will your program print? You don't know, I don't know, the computer doesn't know, nobody knows until you count the number of letters in the word the human typed in at runtime. Java has a built-in "method" -- that's a fancy word for "subroutine", somecode that somebody else wrote but you can use without looking inside, sort of like System.out.print -- that does this count for you.

Alternatively, you could input the word one letter at a time until you get a non-letter, counting as you go, which is convenient because we want the letters in an array anyway. I bet you already know how to do that (in English, but maybe not the array part: just leave it vague for now).

Programming is a lot like mathematics: there are multiple ways to solve most programming problems, and if you don't make any mistakes (or rather, if you fix all the mistakes), pick one you like and go with it, mostly they all get the same results. Sometimes one way is harder or easier to program than another, or runs slower. After you have been programming a while, you will have a feel for which is better.

So this is your program, you pick a way to decide how long the user word is, write as much as you can in English, and then turn the page.

Five Basic Concepts
Sequence
Iteration
Conditional
Variables
Input/Output
<<Previous | ToC | Next >>

Revised: 2021 June 3