chapter 9 Flashcards

1
Q

if you are trying to store words or sentences in Java what is it that you need?

A

If you’re trying to store words or sentences (not just single letters), then you need to use something called a String.

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

what is it you need to choose between 2 different choices in a java program?

A

in order to choose between to options in a java program you will need an if statement

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

what is the basic format for creating an if statement?

A

if(Condition){
SomeStatements
} else{
OtherStatements
}

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

what is an “if clause” and an “else clause”?

A

the “if clause” pertains to the statements written for the “if statements” and the else clause corresponds to the other statements for the else statements.

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

what symbol must an if and else clause be in between of?

A

whether you are writing statements for the “if clause” or the “else clause” you must put the statements within parentheses followed by a semicolon

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

what 2 types of errors often occur without warning when writing if statements in a java program?

A

using a semicolon immediately after the word else will compile without errors but the statements will always be executed whether the condition is true or false

missing curly braces will compile without errors but the program’s run may not do what you expect it to do so make sure you add curly braces

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

how do you write an if statement’s skeletal outline and how is typing the if statement’s skeletal outline help you with writing your code?

A

if () {
} else{
}
when you apply this kind of thinking to a compound statement, it’s harder to make a mistake. just write this first and then fill in the blanks.

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

when using the random method, why must you add a + 1 to the random variable (10) if your intent is to have a range of 1 to 10 ?

A

you must add 1 if you want to get that 1 to 10 range because if not it will be a range of 0 to 9

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

what is “Random” in the Java API?

A

it is a class which stores methods to select a random variable and it’s not limited to just numbers but strings and characters as well.

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

why would a random number created by computers not be truly considered a random number? what are these random numbers that computers generate be called instead?

A

a computer has a pattern to create randomly generated numbers but these numbers arent truly random if you try to create a random number using a computer. these randomly created numbers are called pseudo random numbers

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

why is it important to indent your code?

A

if you don’t indent your statements in some logical fashion, niether you nor anyone else can make sense of your code. indenting helps you the user and the programmer to understand the code.

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

since indentation is important in writing code, what is an easy way to deal with creating neatly indented code?

A

Eclipse has a feature that allows it to automatically indent your code.

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

what happens if you dont write an else clause for your if statement?

A

then if the if clause is activated it will display the if statement’s condition but if not it stays blank and continues with the rest of the code if there is any.

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

how do you compare 2 numbers in an if statement’s statement?

A

you always use a double equal sign.

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

why do you need a double equal sign to compare 2 numbers instead of just 1 equal sign?

A

because 1 equal sign does assignment while a double equal sign does comparisons

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

how would you display the random number after an if statement without an else clause? and why?

A

you would write a println outside of the if statement after the if statement because if you wrote the println within the parentheses of the if statement, then the random number would only display if the random number is activated instead of displaying the random number everytime you run the program.

17
Q

how many statements can you put inside of an if statement?

A

only one for each of the if and else clause.

18
Q

in what way can you fit more than 1 statement within the if and else clause?

A

make sure to use curly braces where it is needed as they act like kind of a block, allowing you to add more than 1 statement for both the if and else clause.

19
Q

how does a block of code containing 2 statements within the if and else clause behave?

A

it acts as if it is a single statement.

20
Q

what is a block statement?

A

it is a couple of statements within a bracket considered one large statement.

21
Q

what part of a program is used to abbreviate code?

A

the ability to abbreviate things is called static import