Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java 1: 1) Choose a for statement header that will vary the control variable x i

ID: 3809913 • Letter: J

Question

Java 1:

1) Choose a for statement header that will vary the control variable x in increments of 5 from 0 up through 100; then choose a for statement header that decrements by 5 from 100 to 0. You don't have to code a body.

Choose all the answers that are correct. All or nothing.

for(int x = 100; x >= 0; x-5)

for(int x = 0; x < 100; x += 5)

for(int x = 0; x <= 100; x += 5)

for(int x = 100; x >= 0; x -= 5)

for(int x = 0; x <= 100; x++)

for(int x = 100; x <= 0; x -= 5)

2) Given:

boolean spinach = false;
boolean lasagna = true;
char salad = 'y';

spinach ^ lasagna && salad == ‘y’

Choose all the answers that are correct. All or nothing.

lasagna && salad == 'y' will be evaluated last.

spinach ^ lasagna will be evaluated first.

The truth value of the complex condition is "true".

The truth value of spinach ^ lasagna will be joined with the truth value for salad == 'y' by the &&.

The truth value of the complex condition is "false".

lasagna && salad == 'y' will be evaluated first.

a.

for(int x = 100; x >= 0; x-5)

b.

for(int x = 0; x < 100; x += 5)

c.

for(int x = 0; x <= 100; x += 5)

d.

for(int x = 100; x >= 0; x -= 5)

e.

for(int x = 0; x <= 100; x++)

f.

for(int x = 100; x <= 0; x -= 5)

Explanation / Answer

1-a for statement header that will vary the control variable x in increments of 5 from 0 up through 100
c- for(int x=0;x<=100;x+=5) as it is starting from 0 and it will go uptill 100 by incrementing 5 everytime.

for statement header that decrements by 5 from 100 to 0
d-for(int x=100;x>=0;x-=5) as it is starting from 100 and it will decrement by 5 untill it becomes 0.

2-The truth value of the complex condition is "true". because salad=='y' is true and spinach^lasagna is also true so combined the complex condition is true.
salad==y will be evaluated first then spinach^lasagna will be evaluated and then && will be evaluated because of the operators precedence.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote