• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 10 pages
Exam (elaborations)

CS 170 Java Final || Questions and 100% Accurate Answers.

Document preview thumbnail
Preview 2 out of 10 pages

A loop that searches for a particular value in input is called a(n) : correct answers sentinel loop final int LASTVAL = -99; Scanner cin = new Scanner(S); int entry = Int(); while (entry != LASTVAL) { int triple = entry * 3; Sln(triple); entry = Int(); } The above code is an example of a(n) ____ while loop. correct answers sentinel-controlled Which executes first in a do...while loop? correct answers statement What is the output of the following Java code? int num = 0; while (num 5) { S(num + " "); num = num + 1; } Sln(); correct answers 0 1 2 3 4 Suppose sum and num are int variables, and the input is What is the output of the following code? Scanner cin = new Scanner(S); sum = 0; num = Int(); while (num != -1) { sum = sum + num; num = Int(); } Sln(sum); correct answers 110 int x = 5; int y = 30; do x = x * 2; while (x y);

Content preview

CS 170 Java Final || Questions and 100% Accurate Answers.
A loop that searches for a particular value in input is called a(n) : correct answers sentinel loop

final int LASTVAL = -99;
Scanner cin = new Scanner(System.in);
int entry = cin.nextInt();

while (entry != LASTVAL)
{
int triple = entry * 3;
System.out.println(triple);
entry = cin.nextInt();
}
The above code is an example of a(n) ____ while loop. correct answers sentinel-controlled

Which executes first in a do...while loop? correct answers statement

What is the output of the following Java code?
int num = 0;
while (num < 5)
{
System.out.print(num + " ");
num = num + 1;
}
System.out.println(); correct answers 0 1 2 3 4

Suppose sum and num are int variables, and the input is
18 25 61 6 -1
What is the output of the following code?
Scanner cin = new Scanner(System.in);
sum = 0;
num = cin.nextInt();
while (num != -1)
{
sum = sum + num;
num = cin.nextInt();
}
System.out.println(sum); correct answers 110

int x = 5;
int y = 30;

do
x = x * 2;
while (x < y);

, If y = 0,
How many times would the loop above execute? correct answers 1

What is the output of the following Java code?
int x = 1;

do
{
System.out.print(x + " ");
x--;
}
while (x > 0);

System.out.println(); correct answers 1

Which of the following is not a function of the break statement? correct answers To ignore
certain values for variables and continue with the next iteration of a loop

Suppose that the input is

5 3 4 -6 8
What is the output of following Java code fragment?
Scanner cin = new Scanner(System.in);
int sum = 0;
int num;
for (int j = 1; j <= 5; j++)
{
num = cin.nextInt();
if (num < 0)
continue;

sum = sum + num;
}

System.out.println(sum); correct answers 20

The hasNext method returns ____ when trying to read past the end of the input file. correct
answers false

Which of the following about Java arrays is true?
(i) All components must be of the same type.
(ii) The array index and array element must be of the same type. correct answers Only (i)

You can create an array of three doubles by writing : correct answers double ar[] = { 1.1, 2.2, 3.3
};

Document information

Uploaded on
March 25, 2025
Number of pages
10
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$11.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
SirAnton
3.7
(118)
Sold
811
Followers
438
Items
40231
Last sold
5 days ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions