Ask Java Expert


Home >> Java

Assignment

QUESTION 1
In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably).
True
False

QUESTION 2
Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?
for (int i=0;i<5;i++)
x += i;

A.0

B.4

C.5

D.10

QUESTION 3
The following loop is syntactically valid.
for (int j = 0; j < 1000; j++) j--;

True
False

QUESTION 4
It is possible to convert any type of loop (while, do, or for) into any other.
True
False

QUESTION 5
If x is an int where x = 0, what will x be after the following loop terminates?
while (x < 100)
x *= 2;
2

64

100

128

none of the above, this is an infinite loop

QUESTION 6
Consider the following switch statement where x is an int. If x is currently equal to 3, what will the value of x be after the switch statement executes?
switch (x)
{
case 3 : x += 1;
case 4 : x += 2;
case 5 : x += 3;
case 6 : x++;
case 7 : x += 2;
case 8 : x--;
case 9 : x++;
}

A- 6

B- 11

C- 10

D- 12

QUESTION 7
A switch statement must have a default clause.
True
False

QUESTION 8
How many times will the following loop iterate?
int x = 0;
do {
System.out.println(x);
x++;
} while (x > 0 && x<10);

A.1 timeB.9 timesC.10 timesD.11 times

QUESTION 9
Control in a switch statement jumps to the first matching case.
True
False

QUESTION 10
The following for-loop is an infinite loop.
int i; for (int j = 0; j < 1000; ) i++;

True
False

QUESTION 11
Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;
A- The condition short circuits and the assignment statement is not executed
B- The condition short circuits and the assignment statement is executed without problem
C- The condition does not short circuit causing a division by zero error
D- The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error

QUESTION 12
The break statement does which of the following?

A- ends the program

B- transfers control out of the current control structure such as a loop or switch statement

C- ends the current line of output, returning the cursor

D- denotes the ending of a switch statement

E- indicates the end of line when using System.out.print

QUESTION 13
The do loop differs from the while loop in that

A- the while loop will always execute the body of the loop at least once

B- the do loop will always execute the body of the loop at least once

C- the do loop will continue to loop while condition in the while statement is false and the while loop will continue to loop while the condition in the while statement is true

D- the while loop will continue to loop while condition in the while statement is false and the do loop will continue to loop while the condition in the while statement is true

E- none of the above, there is absolutely no difference between the two types of loops

QUESTION 14
Of the following if-statements, which one correctly executes three instructions if the condition is true?

if (x < 0)
a = b * 2;
y = x;
z = a - y;

{
if (x < 0)
a = b * 2;
y = x;
z = a - y;
}if { (x < 0)
a = b * 2;
y = x;
z = a - y ;
}

if (x < 0)
{
a = b * 2;
y = x;
z = a - y;
}

QUESTION 15
How many times will the following loop iterate?
int x = 0;
while (x > 0 && x<10)
{
System.out.println(x);
x++;
}

A.0 times

B.1 time

C.9 times

D.10 times

QUESTION 16
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
if (x > 0) x++;
else x--;
if (x > 0) x++;

else if (x < 0) x--;

if (x > 0) x++;

if (x < 0) x--;

else x = 0;

if (x == 0) x = 0;

else x++;

x--;

E) x++;

x--;

QUESTION 17
Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions:
Condition 1: (x < y && x > 0)
Condition 2: (a != d || x != 5)
Condition 3: !(true && false)
Condition 4: (x > y || a == 'A' || d != 'A')

All 4 Conditions are true, Only Condition 2 is true, Condition 2 and Condition 4 are true only, Conditions 2, 3 and 4 are all true, Condition 1 is not, All 4 Conditions are false

QUESTION 18
You might choose to use a switch statement instead of nested if-else statements ifthe variable being tested might equal one of several hundred int valuesthe variable being tested might equal one of only a few int valuesthere are two or more int variables being tested, each of which could be one of several hundred valuesthere are two or more int variables being tested, each of which could be one of only a few valuesnone of the above, you would never choose to use a switch statement in place of nested if-else statements under any circumstance.

QUESTION 19
The statement if (a >= b) a++; else b--; will do the same thing as the statement if (a < b) b--; else a++;.
True
False

QUESTION 20
Consider the following switch-statement where x is an int. If x is currently equal to 5, what will the value of x be after the switch statement executes?

switch (x)
{
case 3 : x += 1;
case 4 : x += 2;
case 5 : x += 3;
case 6 : x++;
case 7 : x += 2;
case 8 : x--;
case 9 : x++;
}

A.8

B.6

C.11

D.5

Java, Programming

  • Category:- Java
  • Reference No.:- M92503956
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As