What will be printed by the following code


#.Match terminology to definitions.?


branch

conditional execution

control structure

counter

cumulative algorithm

factoring

relational operator

roundoff error


#.Indicate the order of the flow of control for an if statement.?

#.Match each operator to its function.?

Matching pairs

!=

&&

<

<=

=

==

>

>=

||


#. Given the following variables?

int x = 1;
int y = 2;
int z = 3;

Evaluate each of the following tests.

Matching pairs

x == y

x != y

y < z

x + y <= z

x + y > z

y >= z


#.What will be printed by the following code?

int x = 1;
int y = 2;
if (x == y) {
x = x + 1;
}
System.out.print(x);
if (x < y) {
x = x - 1;
}
System.out.print(x);



1. 22

2. 10

3. 11

4. 2

5. 0

6. 1

7. 21

#.Let s1 and s2 be two String variables. Which is the best test for determining whether s1 and s2 are equal?



1. s1 == s2

2. s1 = s2

3. String.equals(s1, s2)

4. s1.equals(s2)

5. equals(s1, s2)


#.Suppose money1 and money2 are two double variables that represent amounts of money in dollars and cents. Which test is the most appropriate for testing the equality of the values?



1. Math.round(100 * money1) == Math.round(100 * money2)

2. money1.equals(money2)

3. money1 == money2

4. Math.abs(money1 - money2) < 0.001

5. money1 = money2

6. money1 / money2 == 1


#.Consider the following code:

int count = 0;
for (int i = 1; i <= 10; i++) {
if (i == i) {
count++;
}
}
System.out.println(count);

Suppose the test i == i is replaced with another test. What will the code print for each replacement test below?




i < 4 && i > 7

i < 4 || i > 7

i > 4 && i < 7

i > 4 || i < 7


#. The following method returns the next value in a hailstone sequence given the current value as a parameter.

public static int hailstone(int current) {
int next;
if (current % 2 == 0) {
next = current / 2;
} else {
next = 3 * current + 1;
}
return next;
}

Determine the value of each of the following method calls.



Matching pairs
hailstone(24)

hailstone(3)

hailstone(5)

hailstone(hailstone(9))



#.
The following method is supposed to calculate the next 10 values in a hailstone sequence starting with a given value. It should return the minimum of the next 10 values.?

public static int hailstoneMin(int start) {
int next = hailstone(start);
// need initialization
for (int i = 2; i <= 10; i++) {
next = hailstone(next);
// need update
}
// need return
}

Select replacements for the comments so that the method performs its task.



Matching pairs
replace // need initialization

replace // need update

replace // need return

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: What will be printed by the following code
Reference No:- TGS097217

Expected delivery within 24 Hours