Module 5 Flashcards
Which of the following loops would print out a list of even numbers ranging from 1 through 10?
Formatting impossible, See print version
Formatting impossible, See print version
What are the two main components of an iterative loop in Java?
A) A subordinate scope of program code.
B) Its opening and closing round parentheses.
C) The evaluation of a boolean expression yielding either true or false.
F) It’s opening and closing curly brackets.
A) C)
Which of the following are valid elementary conditional clauses?
Formatting Error - see text
Formatting Error see text
Please select the expression or expressions below which identify the purpose of a ! sign in a conditional clause
A) Terminates an action statement.
B) Specifies the negation of an elementary equals operator.
C) Precedes an if statement
D) Reverses the logical sense of a conditional clause.
B) D)
A and C are incorrect. B refers to the elementary conditional operator !=, and D refers to the compound conditional operator !.
Please select all of the clauses below which indicate an aspect of the if statement
A) A conditional statement
B) Followed by one or more action clauses
C) Can alter the flow of the program execution
D) Capable of assigning a value
E) Followed by an open round parenthesis
A) B) C) E)
The if statement cannot assign a value. All other Feedback: statements are true.
Which Java iterative procedure(s) may never execute its subscope?
A) for
B) do/while
C) do until
D) while
A) D)
Which of the following Java statements will tell if the two dogs defined in this scenario have the same name?
String dogname1 = new (“Rover”);
String dogname2 = new (“Rover”);
A) if (dogname1 == dogname2)
B) if (dogname1.equals (dogname2))
C) if (dogname1[0] == dogname2 [0])
D) if (dogname1.length() == dogname2.length())
B)
Which iterative procedure in Java always executes the subscope of code at least once?
A) while
B) for
C) do…while
D) do until
C)
Please identify all of the conditional operators which occur in the list below.
A) >=
B) =
C) +
D) !=
E) &&
A) D)
! is the compound Not operator, && is the compound AND operator, and >= is the elementary greater-than-or-equals operator. + is the arithmetic addition operator and = is the assignment operator.
What will be printed by the following Java program?
public class Scope_of_i
{
public static void main (String [] args)
{
int i;
for (i=1; i<3; i++)
{
System.out.print (i);
}
System.out.print (i+1);
}
A) 121
B) 124
C) 1224
D) This program would not compile
B)
What will the value left in i be after the following Java code is executed?
int i=0;
for (int j = 0; j < 5; j = j + 2)
i += j;
A) 0
B) 15
C) 6
D) 10
C)
The loop will execute three times when j is 0, 2, 4. Each time through the loop j is added to i so the sum will be 6.
What is the outcome of the following code?
int a = 5, b = 10, sum = 0;
if ((a++ == 5) && (b++ == 10)) {
sum = a + b;
}
System.out.println(a + “,” + b + “,” + sum);
A) 5, 10, 17
B) 6, 11, 17
C) 5, 10, 15
D) 5, 10, 0
B)
Since the ++ is post increment, if test evaluates to true. At this point, a and b are increments resulting in 6, 11, and the sum as 17
Which of the following is a valid header of the Java for statement?
A) for (double i = 1; i<=5; i++)
B) for (int i=1; i>=5; i–)
C) for (int i = 5; i>0; i–)
D) for (int i>1; i=5; i++)
E) for (int i = 1; i <=5; i++)
C) E)
Which of the following statements are true regarding the Java do…while statement ?
A) The subscope of the loop is not executed following the do keyword.
B) The do keyword appears at the top of the loop and the while at the bottom.
C) Testing is done prior to entering the subscope of the loop.
D) Testing is done following the subscope of the loop.
E) The subscope of the loop is executed once before testing to continue the iteration.
B) D) E)
What will be printed by the following code?
int x = 12;
if ( x < 5 || x > 15 )
System.out.println (“1”);
else if ( x > 5 && x < 10 )
System.out.println (“2”);
else
System.out.println (“3”);
A) 3
B) 1
C) 2
D) Nothing
E) 1 2
A)