How many times will line 7 be executed when the following code is run?


String str = "rebellion";

int i = 0;

int j = str.length() - 1;

String result = "";

while (i < j)

{

result = str.substring(i, i + 1) + result + str.substring(j, j + 1);

i++;

j--;

}

System.out.println(result);
(Java)

Answers

Answer 1

Answer:

4 times

Explanation:

Required.

How many times will line 7 be executed?

Line 2 initialises i to 0

Line 3 subtracts 1 from the length of "rebellion" , the result of the subtraction is then saved in J

So:

j = 9 - 1

j = 8

From line 2 and line 3, we have that:

i = 0 and j = 8

Line 4 is an iteration that is repeated as long as i is less than j

Line 7 will be executed, for the first time as: i < j because 0 < 8

i is incremented to 1 and j is reduced to 7

Line 7 is then executed again, the second time because 1 < 7

i is incremented to 2 and j is reduced to 6

Line 7 is then executed again the third time because 2 < 6

i is incremented to 3 and j is reduced to 5

Line 7 is then executed again the fourth time because 3 < 5

i is incremented to 4 and j is reduced to 4

At this stage, line 7 will no longer be executed because I is no longer less than as 4 = 4.

Hence, number of execution is 4 times


Related Questions

Amanda would like to add text to a slide in her presentation. Select all of the correct methods she can use to add text.
Select "Text" from the Insert menu.

Click in the Task pane and enter text.

Draw a text box, click in it, and enter text.

Click in a placeholder and enter text.

PLEASE help

Answers

Answer:

Draw a text box

Explanation:

Because if she draw it she can edit and write what she want

Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smallest and largest integers in the list.

Ex: If the input is:

10
5
3
21
2
-6
the output is:

2 and 21

Answers

n = 1

lst = []

while n > 0:

   lst.append(n := int(input()))

lst.pop(-1)

print(str(min(lst)) +" and "+str(max(lst)))

I wrote this code in python 3.8. I hope this helps

Ryan is a manager who maintains an official record of the events that happen in his company. At the end of the day, he writes about the events that took place. The words that he frequently mentions in his record are today, client, and meeting. The moment he types the first two letter of these words, they appear as a suggestion. Which feature of the word processing program makes these suggestions

Answers

Answer: word completion

Explanation:

Answer:

Word Completion

Explanation: because i took the test.


If you wanted readers to know a document was confidential, you could include a ____ behind the text stating
"confidential".
watermark
theme
text effect
page color

Answers

I have no idea for that

Answer:

watermark

Explanation:

The U.S. military's standard for computer security is known as
DCS-3000.
TEMPEST.
Daubert standard.
Carnivore.

Answers

Answer:

TEMPEST.

Explanation:

TEMPEST is an acronym for Telecommunications Electronics Materials Protected from Emanating Spurious Transmissions and it is a secret (classified) project of the government of the United States of America that originated with its military in the 1960s based on the study of security with respect to telecommunication devices emitting Electromagnetic Radiation (EMR).

Hence, the U.S. military standard for computer security is known as TEMPEST.

The main purpose of the Telecommunications Electronics Materials Protected from Emanating Spurious Transmissions (TEMPEST) is to prevent the theft, compromise or interception of informations that are being transmitted on various telecommunications devices through the use of Electromagnetic Radiation (EMR).

Learning Task 3: Below are different electronic diagrams. Write the name of
the diagram on your answer sheet.
BELL
Input
Video
Transform
Quantization
Entropy
Coding
Output
Bitstream
Inverte
Quantization
1 2 3
Inverse
Transform
Number to be
dropped when
energized by
electric current
Annunciato
DOOD
Intor intra
Prediction
Frame
Buffer
Ordinary
Push Button​

Answers

Answer:

WAOW

Explanation:

You did better than I can

dad always arrives home from work thoroughly exhausted​

Answers

Yes plz explain your answer
Other Questions
Which of the numbers shown in the box below is the largest? 19/3, 31/5, 13/2, 25/4 pls help urgent Why is Lucrezia Borgia famous? And how was her education? Discuss what affects your food choices more: you own taste or what foodsare available you. Do you make good food choices? Explain.Help me with that please Aditi can walk 1.7 miles in half an hour. At the same constant speed, how many hours would it take her to walk 17 miles? Energy can be neither created nor destroyed. This fact means that even though energy sources can be depleted (used up), the energy in them is not destroyed. Instead, it is transformed to other forms of energy. And almost all energy resources here on Earth can have their energy traced back to the Suns gravitational or light energy.Electricity is often thought of as a secondary source of energy because it must be gained by transforming some other kind of energy (a primary source). Think about where the electricity generated by a wind turbine comes from. Describe the path that wind energy takes from the Suns light to electricity.plz help ioo pointshurry Sam is buying music online. He can download 48 songs in 3 minutes. How many minutes will it take to download 128 songs? How does the author use tone to advance her purpose? Why do you think there has been an interest in automating the voting process in recent times? What is the equation of the line that has a slope of -3 and passes through the point (-2, 4)?O y = -3x - 2y=-3xy=-3x - 4y = -3x + 4O y=-3x + 2 A bookstore pays $28 for a copy of atextbook. The bookstore sells the textbookfor $42. What is the percent markup on thetextbook?F 14%G 33%H 50%3 67% Draw Conclusions The text states that the Dawes Act of 1887 and theAmerican Indian Citizenship Act of 1924 were both designed to helpAmericanize the Native Americans. Explain the negative effects of these laws. HelpWhich answer choice shows 3.002 written in expanded form?OA) 3 + 0.2OB) 3 + 0.02OC) 3 + 0.002OD) 3 + 0.0002 Where is the blue dot on the number line? Plz help. Will give brainliest for the best answer The only nonmetal in Group 14 isA carbon.B. oxygen.C. nitrogen.D. fluorine. guysss...need help in this.....itz all in the pic....;)plz answer it...to get brainliest....thx Just do q1-4 and hurry...... hes coming for me! During the process of meiosis, chromosomes are divided evenly, so that the sex cell receives ONE chromosome from each homologous set. What are these sex cells called? I NEED HELP ASAP!!World history Describe how different types of motion are represented by distance-time graphs and velocity-time graphs.