chapter 9 Flashcards
if you are trying to store words or sentences in Java what is it that you need?
If you’re trying to store words or sentences (not just single letters), then you need to use something called a String.
what is it you need to choose between 2 different choices in a java program?
in order to choose between to options in a java program you will need an if statement
what is the basic format for creating an if statement?
if(Condition){
SomeStatements
} else{
OtherStatements
}
what is an “if clause” and an “else clause”?
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.
what symbol must an if and else clause be in between of?
whether you are writing statements for the “if clause” or the “else clause” you must put the statements within parentheses followed by a semicolon
what 2 types of errors often occur without warning when writing if statements in a java program?
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 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?
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.
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 ?
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
what is “Random” in the Java API?
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.
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 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
why is it important to indent your code?
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.
since indentation is important in writing code, what is an easy way to deal with creating neatly indented code?
Eclipse has a feature that allows it to automatically indent your code.
what happens if you dont write an else clause for your if statement?
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 do you compare 2 numbers in an if statement’s statement?
you always use a double equal sign.
why do you need a double equal sign to compare 2 numbers instead of just 1 equal sign?
because 1 equal sign does assignment while a double equal sign does comparisons