









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










โโ Java Expression not equal to. Answer: != โโ Java expression greater than. Answer: > โโ Java expression greater than or equal to. Answer: >= โโ Java expression less than. Answer: < โโ Java expression less than or equal to. Answer: <= โโ What is the data type of a comparison expression. Answer: boolean โโ For comparison operators that have two symbols, is there a space present?. Answer: no โโ For comparison operators does the equals sign come first or second.. Answer: Always second โโ The condition of a Java if statement must be,. Answer: Boolean
contained in parentheses โโ compound statement. Answer: a list of statements enclosed in a pair of braces โโ Each branch of a Java if statement consists of at most. Answer: one statement, although the statement may be compound. โโ Suppose n1 and n2 are two int variables that have been given values. Write a Boolean expression that returns true if the value of n1 is greater than or equal to the value of n2; otherwise, it should return false.. Answer: n1 >= n โโ Suppose n1 and n2 are two int variables that have been given values. Write an if-else statement that outputs "n1" if n1 is greater than or equal to n2, and that outputs "n2" otherwise.. Answer: if (n1 >= n2) System.out.println("n1"); else System.out.println("n2"); โโ Are braces optional for if single controlled statements. Answer: yes
โโ Dr Java is an IDE which stands for. Answer: Integrated Development Environment โโ What do IDE's bundle together. Answer: code editor, compiler, and debugger โโ code editor. Answer: colorizes and indents code โโ compiler. Answer: clickable error messages that move the edit cursor to the location of the error โโ State the recommended five steps to follow when writing a program. Answer: analysis program design test design coding test execution and debugging โโ State questions that should be asked and answered during analysis.. Answer: What is the overall goal? What are the inputs and outputs? What are the detailed requirements? What hints/helps are provided?
โโ pseudocode. Answer: statements that describe what you want the code to do without worrying about ()'s, {}'s, ;'s, order of vars in assignment, ==, etc. โโ why is it simpler to write pseudocode than java code. Answer: because there is No need to worry about ()'s, {}'s, ;'s, order of vars in assignment, ==, etc. only what you want the program to accomplish. โโ why it is recommended to perform program design prior to coding?. Answer: to avoid mistakes, make sure you understand the program, and save time โโ why it is recommended to design program tests before writing Java code?. Answer: to help understand the problem and helpthink of different situations that can occur and troubleshoot problems in the code that might occur before testing the code. โโ how does the Java switch statement is similar to and different from a if-else statement. Answer: similar: only other kind of java statement that implements multiway branching
โโ What is the output produced by the following code? int key = 1; switch (key + 1) { case 1: System.out.println("Apples"); break; case 2: System.out.println("Oranges"); break; case 3: System.out.println("Peaches"); case 4: System.out.println("Plums"); break; default: System.out.println("Fruitless"); }. Answer: oranges
โโ What would be the output in Self-Test Exercise 10 if the first line were changed to the following? int key = 3;. Answer: plumes โโ What would be the output in Self-Test Exercise 10 if the first line were changed to the following? int key = 5;. Answer: fruitless โโ Suppose variable1 and variable2 are two variables that have been given values. How do you test whether they are equal when the variables are of type int? How do you test whether they are equal when the variables are of type String?. Answer: When the variables are of type int, you test for equality using ==, as follows: variable1 == variable When the variables are of type String, you test for equality using the method equals, as follows: variable1.equals(variable2)
programsDone are both of type int.. Answer: if ( (exam >= 60) && (programsDone >= 10) ) System.out.println("Passed"); else System.out.println("Failed"); โโ Write an if-else statement that outputs the word "Emergency" provided the value of the variable pressure is greater than 100 or the value of the variable temperature is greater than or equal to 212. Otherwise, the if-else statement should output the word "OK". The variables pressure and temperature are both of type int.. Answer: if ( (pressure > 100) || (temperature >= 212) ) System.out.println("Emergency"); else System.out.println("OK"); โโ Determine the value, true or false, of each of the following Boolean expressions, assuming that the value of the variable count is 0 and the value of the variable limit is 10. (Give your answer as one of the values true or false.) a. (count == 0) && (limit < 20)
b. count == 0 && limit < 20 c. (limit > 20) || (count < 5) d. !(count == 12) e. (count == 1) && (x < y) f. (count < 10) || (x < y) g. !( ((count < 10) || (x < y)) && (count >= 0) ) h. ((limit/count) > 7) || (limit < 20) i. (limit < 20) || ((limit/count) > 7) j. ((limit/count) > 7) && (limit < 0) k. (limit < 0) && ((limit/count) > 7). Answer: a. true. b. true. Note that expressions a and b mean exactly the same thing. Because the operators == and < have higher precedence than &&, you do not need to include the parentheses. The parentheses do, however, make it easier to read. Most people find the expression in option a easier to read than the expression in option b, even though they mean the same thing. c. true. d. true. e. false. Because the value of the first subexpression, (count == 1), is false,
you know that the entire expression is true without bothering to evaluate the second subexpression. Thus, the second subexpression, ((limit/count) > 7), is never evaluated, so the fact that it involves a division by zero is never notic โโ Does the following sequence produce a division by zero? int j = - 1; if ((j > 0) && (1/(j+1) > 10)) System.out.println(i);. Answer: No. Since (j > 0) is false and Java uses short-circuit evaluation for &&, the expression (1/(j+1) > 10) is never evaluated. โโ Convert the following expression to an equivalent fully parenthesized expression: bonus + day * rate / correctionFactor * newGuy - penalty. Answer: ((bonus + (((day * rate) / correctionFactor) * newGuy)) - penalty) โโ while statement. Answer: used to repeat a portion of code (i.e., the loop body) based on the evaluation of a Boolean expression โโ for statement. Answer: most commonly used to step through an integer variable in equal increments
โโ do-while statement. Answer: used to execute a portion of code (i.e., the loop body), and then repeat it based on the evaluation of a Boolean expression โโ for statement(____,______,______). Answer: initializing, boolean_Expression, update โโ differencce between while and do-while. Answer: do-qhile is useful when we want to execute the loop body at least once โโ can java while and for loops do the same thing. Answer: yes โโ infinite loops. Answer: the boolean expression remains true, making the loop run forever โโ Which Java expressions are especially prone to loops. Answer: == and != โโ sentinel value. Answer: an illegal value that is used to end a list of values โโ nested loops. Answer: inner loop iterates from beginning to end for each single iteration of the outer loop
โโ Explain how to overcome limitations of the provided robot methods-