![frandariusscott](/avatars/826.jpg)
frandariusscott
15.11.2021 •
Mathematics
The following for loop prints the numbers 1 to 20 on one line with a space between.
for (int i = 1; i <= 20; i++)
{
System.out.print(i + " " ); // prints each value of i followed by a space on one line
}
Question
Consider the for loop example above. Assume you want to adjust the loop to print only the even values from 1 and 20. What must the loop elements - counter initialization, conditional statement, and counter modification - be set to in order to accomplish the goal.
Review all options listed below carefully. You MUST select 3 answers; one for each element/category:
Counter initialization
Conditional statement
Counter modification
a. int i = 0;
b. int i = 1;
c. int i = 2;
d. i < 20;
e. i <= 20;
f. i > 20;
g. i++;
h. i+=1-;
i. i+=2;
Solved
Show answers
More tips
- T Travel and tourism Lost in the Catacombs: What to Do?...
- L Leisure and Entertainment What to Bring on a Hike? Essential Items to Pack for a Safe and Enjoyable Adventure...
- S Style and Beauty How Are Eyelash Extensions Applied? All Your Questions Answered...
- F Family and Home Tender Care for Your Parquet: Is it Possible to Clean Parquet?...
- S Society and Politics Is It Fact or Fiction? Let s Talk About Anton Chekhov s Pseudonym...
- S Sport Playing Bowling: Rules and Advice for Novices...
- C Computers and Internet How to Properly Repartition a Hard Drive?...
- A Auto and Moto What Is the Cost of Customs Clearance for a Car in Russia?...
- L Leisure and Entertainment Should You Buy a Ceramic Knife?...
- C Computers and Internet How to easily and quickly disable Firebug in Gmail and Google Docs...
Answers on questions: Mathematics
- M Mathematics Out of the 83 peices of candy in the bag, Fred couldn t eat 15 of them. What percent of candy could Fred not eat? (Round to the nearest whole number)...
- M Mathematics Factorise the following expression :...
- M Mathematics -23.5 + (-18.9)= plzz help...
- M Mathematics I need help with my assignment........
- M Mathematics Deriving and using for Shen has a box that contains t toys. Write an expression for the total number t of toyshe has in the box when:he puts in 4 more...
- M Mathematics Factorise the following :...
- M Mathematics 9 x ( 8 divided 1^3 )...
- M Mathematics Factorise the following expressions.7p^2 + 49pq...
- M Mathematics Factorise the following expression :...
- M Mathematics Can someone help me with this question ..... just number 4...
Ответ:
Counter initialization:
.
Conditional statement:
.
Counter modification:
.
Step-by-step explanation:
In the current Java for-loop in this question:
The counter initialization statementThe even integers between
and
includes
. It would be necessary to add
each time to get to the next number.
Since the list of even integers starts at
, it would be necessary to initialize the counter variable to
rather than
. Thus, replace the counter initialization statement
with
.
The maximum integer that this loop should print is still
. Thus, the conditional statement
does not need to be changed.
The for-loop should add
to the counter each time to get to the next even integer. Thus, the counter modification statement
(or equivalently,
) should be replaced with
.
Overall, the for-loop should be:
Ответ:
no and yes. No because you got a good grade and yes because this is 10% of your grade, But even if it goes down it wouldn't make you fail or go down by a lot of %.