Filters
Question type

Study Flashcards

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt") ;


A) System.out.println(diskOut, "Calvin") ;
B) PrintWriter.println("Calvin") ;
C) DiskFile.println("Calvin") ;
D) diskOut.println("Calvin") ;

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

In all but very rare cases, loops must contain, within themselves


A) nested loops
B) a way to terminate
C) arithmetic operators
D) nested decision strucures

E) None of the above
F) B) and C)

Correct Answer

verifed

verified

Which of the following statements will create an object from the Random class?


A) randomNumbers() = new Random() ;
B) Random myNumber = new Random() ;
C) myNumber = new Random() ;
D) Random = new randomNumbers() ;

E) All of the above
F) B) and D)

Correct Answer

verifed

verified

B

How many times will the following do-while loop be executed? int x = 11; Do { X += 20; } while (x <= 100) ;


A) 5
B) 4
C) 3
D) 1

E) B) and D)
F) A) and C)

Correct Answer

verifed

verified

A

A random number, created as an object of the Random class, is always a(n) __________.


A) object
B) integer
C) float
D) class

E) A) and B)
F) All of the above

Correct Answer

verifed

verified

A loop that repeats a specific number of times is known as a(n) __________ loop.


A) count-controlled
B) infinite
C) conditional
D) pretest

E) None of the above
F) All of the above

Correct Answer

verifed

verified

When you open a file with the PrintWriter class, the class can potentially throw an IOException.

A) True
B) False

Correct Answer

verifed

verified

True

The while loop is always the best choice in situations where the exact number of iterations is known.

A) True
B) False

Correct Answer

verifed

verified

The __________ loop is ideal in situations where the exact number of iterations is known.


A) for
B) while
C) do-while
D) posttest

E) A) and B)
F) B) and D)

Correct Answer

verifed

verified

Before entering a loop to compute a running total, the program should first


A) set the accumulator variable to an initial value, often zero
B) set all variables to zero
C) read all the values into main memory
D) know exactly how many values there are to total

E) A) and D)
F) A) and B)

Correct Answer

verifed

verified

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in) ; System.out.print("Enter a number: ") ; Int number = keyboard.nextInt() ; While (number < 100 && number > 500) { System.out.print("Enter another number: ") ; Number = keyboard.nextInt() ; }


A) Numbers less than 100 or greater than 500
B) Numbers in the range 100 - 499
C) Numbers in the range 100 - 500
D) Impossible - the boolean condition can never be true

E) A) and B)
F) All of the above

Correct Answer

verifed

verified

How many times will the following do-while loop be executed? int x = 11; Do { X += 20; } while (x > 100) ;


A) 0
B) 1
C) 5
D) 4

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

What will be the values of x and y as a result of the following code? int x = 25, y = 8; X += y++;


A) x = 34, y = 9
B) x = 25, y = 8
C) x = 33, y = 8
D) x = 33, y = 9

E) All of the above
F) A) and C)

Correct Answer

verifed

verified

Which of the following are pre-test loops?


A) while, for, do-while
B) while, do-while
C) while, for
D) for, do-while

E) B) and C)
F) None of the above

Correct Answer

verifed

verified

What will be the value of x after the following statements are executed? int x = 10; For (int y = 5; y < 20; y +=5) X += y;


A) 25
B) 30
C) 50
D) 40

E) C) and D)
F) A) and D)

Correct Answer

verifed

verified

The variable used to keep a running total in a loop is called a(n) __________.


A) accumulator
B) sentinel
C) summation
D) integer

E) All of the above
F) B) and C)

Correct Answer

verifed

verified

What will be the values of x aand y after the following code is executed? int x = 12, y = 5; X += y--;


A) x = 12, y = 5
B) x = 16, y = 4
C) x = 17, y = 5
D) x = 17, y = 4

E) All of the above
F) A) and D)

Correct Answer

verifed

verified

Select all that apply. Which method of the Random class will return a random number within the range of 0.0 and 1.0?


A) nextDouble()
B) nextLong()
C) nextFloat()
D) nextInt(int n)

E) B) and C)
F) A) and C)

Correct Answer

verifed

verified

The variable that controls the number of times a loop iterates is known as a(n) __________.


A) counter variable
B) loop control variable
C) running total
D) decrement variable

E) B) and C)
F) All of the above

Correct Answer

verifed

verified

In a for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

A) True
B) False

Correct Answer

verifed

verified

Showing 1 - 20 of 56

Related Exams

Show Answer