answers correctly solved 2025
What is a Boolean? How is it different than a String or an Integer? - correct
answer A boolean variable is usually used to indicate whether a particular
condition is true but it can also be use to represent any situation that has two
states, such as a light bulb being turn on and off. Returns a value of true or
false. Reserve word.
Differs because it only returns true or false. It cannot be converted to any
other data type, nor can any other data type be converted to a boolean value.
True and False are also reserve words.
pg 72 Lewis and Loftus
How do you set up an if block? How many branches can an if block contain?
When are curly braces required? - correct answer an if block is an if
statement, otherwise known as a condition statement. If statement starts with
the reserve word if followed by a boolean expression in ( ) followed by
{ statement } to which a statement is executed if true or skipped to the next
statement if false.
"if (this) { do this. }"
if (count > 20)
{
System.out.println("Count Exceed.");
}
,A block statement is a collection of statements enclosed in braces.
e.g.
{
System.out.println("That is not correct, sorry");
System.out.println("The number was " + answer);
}
An if block can contain multiple if statements within it however, you should use
an else statement along with it.
It is good practice to enclose your statements in { } though you do not have to.
Indentation should be proper enough.
pg 192-210 Lewis and Loftus
How do you set up a do loop? How many times does the loop run if you have
count++ inside of the condition? How many times does the loop run if you
have ++count inside of the condition? - correct answer A do statement is
similar to the while statement except that its termination condition i s at the
end of the loop body.
"do { this } while ( this )"
do { statement } while (expression);
The body of the do loop continues until the while clause that contains the
boolean condition that determines whether the loop body will be executed
again.
, ++count and count++ will continue to run as long as the condition is true.
Once false, the program will seek the while condition.
pg 261-264 Lewis and Loftus
What is the difference between count++ and ++count? - correct answer The
increment and decrement operators can be applied after and before the
variable. Before is prefix and after is postfix. When used alone in a statement ,
the prefix and postfix are functionally the same. However, when such a for is
written as a statement by itself, it is usually written in postfix form. When the
increment or decrement operator is used in a larger expression, it can yield
different results depending on the form used. always yield to the side of
readability.
pg 79 Lewis and Loftus
What is the result if you say ? What is the result if you say 9..0?
What is the result if you say 9L / 10L? What is the result if you say 9.0F /
10.0F? - correct answer 9/10 where both values are integers, will return a an
integer (a whole number.)
9.0/10.0 where both values are floating point values, will return a floating point
value. (decimal)
9/10.0 one is an integer and the other is a floating point value, will a floating
point value. (decimal).
9L / 10L turns the values into long integer. This will return a long integer (a
whole number).