chapter 5 Flashcards
how do you fetch a set of characters from the keyboad?
was how to fetch characters from the computer keyboard. There are lots of ways to do it, but the one I recommend in this chapter is keyboard.nextLine()
how does keyboard.nextLine() work?
Calling the nextLine method doesn’t just scoop characters from the keyboard. When the computer runs your program, the computer substitutes whatever you type on the keyboard in place of the text keyboard.nextLine().
if you want just a word for input do you use keyboard.nextLine() ?
But to read a word of input, you don’t call nextWord. (The Java API has no nextWord method.) Instead, to read a word, you call next. keyboard.next()
how do you input from the keyboard a number with no decimal point in it?
nextInt()
how do you input from the keyboard a number with a decimal point in it?
nextDouble()
how do you input from the keyboard a word (ending in a blank space)
next()
how do you input from the keyboard a line (or what remains of a line after you’ve already read some data from the line) ?
nextLine()
how do you input from the keyboard a single character (such as a letter, digit, or punctuation character)
findWithinHorizon(“.”,0.charAt(0)
```
~~~
what are the 3 main lines that help the computer read input from the keyboard?
The three lines are
import java.util.Scanner;
Scanner keyboard = new Scanner(System.in);
keyboard.close();
what is the bad news and good news about the reasoning to understand the 3 main lines of code in a Scanner Class?
the bad news it’s difficult to understand the reasoning behind the 3 lines
the good news is you dont have to understand the reasoning behind these 3 lines.
just be sure to put these lines in the right places
in what order should the 3 main lines in a Scanner class be placed?
import java.util.Scanner line the first line in your program.
keyboard = new Scanner(System.in) line inside the main method immediately after the public static void main(String args[]) { line.
keyboard.close() line the last line in your program.
should you expect for your code to run the first time you compile your program?
It’s unusual for a program to compile and run correctly the first time. There’s almost always a typo or another error of some kind.
what’s a good thing to practice before you run your program?
Don’t assume that you’ve typed words correctly, that you’ve capitalized words correctly, or that you’ve matched curly braces or parentheses correctly. Compare the code you typed with any sample code that you have. Make sure that every detail is in order.
where in the editor does it display a compile time error if your program needs fixing?
When Eclipse finds a compile-time error, the editor usually displays at least three red error markers. The marker in the editor’s left margin has an X-like marking and sometimes a tiny light bulb. The marker in the right margin is a small square. The marker in the middle is a jagged red underline.
what is the name of the option that allows you to automatically correct an error? how do you activate this option?
If you hover the mouse cursor over any of these markers, Eclipse displays a message that attempts to describe the nature of the error. If you hover over the jagged line, Eclipse displays a message and possibly a list of suggested solutions. (Each suggested solution is called a quick fix.) If you right-click the left margin’s marker (or control-click on a Mac) and choose Quick Fix in the resulting context menu, Eclipse displays the suggested solutions. To have Eclipse modify your code automatically (using a suggestion from the quick-fix list), either single-click or double-click the item in the quick-fix list. (That is, single-click anything that looks like a link; double-click anything that doesn’t look like a link.)