Chapter 9 Flashcards

1
Q

What is the basic format for if statements and else statements

A

If (condition ) {
(Some statement) {
} Else {
(Other statement)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an example of a compound statement?

A

And if statement is an example of a compound statement made up of other statements within the if statemen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an if clause and an else clause

A

And if and else clause comes after the if statement and the else statement. The the clauses are performed if the statements are true. Make sure after you write if or else that you start the parentheses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When writing if statements and else statements what is a rule to follow

A

You want to put the if and else statement within parentheses when writing out these statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the rule to follow when writing if statements and else statements when it comes to semicolons?

A

There are no semicolons within the if statement and it’s condition as well as the else condition but there can be semicolons within the else and if clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s one way to write if an else statements without making too many mistakes?

A

You want to write the skeletal framework if an else statement before you fill in the blanks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

According to this program listing 9-2

import java.util.Scanner;
import java.util.Random;
class AnswerYesOrNo {

public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
Random myRandom = new Random();
int randomNumber; System.out.print(“Type your question, my child: “); keyboard.nextLine();
randomNumber = myRandom.nextInt(10) + 1;
if (randomNumber > 5) { System.out.println(“Yes. Isn’t it obvious?”); }
else { System.out.println(“No, and don’t ask again.”); }
keyboard.close();
}
}

What are the parts in the program and listing 9-2 and How many parts in the program’s actions When running the program’s actions for listing 9-2

A

One.
Prompt the user
Number two
Get the question from the user
Number three
Get a random int number from 1 to 10
Number four
Answer yes or no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s something to note about when it comes to random numbers created by a computer language?

A

There are no random numbers that a computer can create instead scientists call this pseudo random numbers as they are created by a set pattern that seems like randomly generated numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is it important to indent your coade?

A

The code may still run on your computer if you don’t indent in an orderly logical fashion but to other programmers and yourself the code may not make sense

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it more important to have meat logical organized indented code and a larger program versus a smaller program?

A

Because the larger the program is the more confused the person will get as they go along reading the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the quickest and easiest way to invent your code on eclipses IDE?

A

There are options in the menu screen that allow you to format an inventor code automatically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When it comes to comparing two values with an equal sign what is one rule to remember

A

Never ever use an equal sign to compare to values make sure you use double equal signs to compare to values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How many statements can you put inside of a nest clause or else clause and why?

A

You can only put one statement anything in between the curly braces acts like a box and is a statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you notice that in your program there are pieces of your code that repeats over and over again that is used a lot like system.out.prints in your code what can you do so you can minimize your typing? Give an example

A

You can abbreviate some of your code by implementing “import static java.lang.” followed by whatever your trying to abbreviate . Note that whatever you put after java.lang, will only abbreviate part of it. For example if you write System.out or System.in , you still have to write out or in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly