Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Draw a table that shows the value of the variables i and n during the execution of loop. The table should contain one column


1. Draw a table that shows the value of the variables i and n during the execution of loop. The table should contain one column for each variable and one line for each iteration.

2. What is the output of this program?

3. Can you prove that this loop terminates for any positive value of n?

public static void main(String[] args) {

loop(10);

}

public static void loop(int n) {

int i = n;

while (i > 1) {

System.out.println(i);

if (i % 2 == 0) { i = i / 2;

} else { i = i + 1; }

}

}

 


Step by Step Solution

There are 3 Steps involved in it

Step: 1

1 Table showing the value of variables i and n during the execution of the ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elementary Statistics

Authors: Neil A. Weiss

8th Edition

321691237, 978-0321691231

More Books

Students also viewed these Programming questions

Question

Define EPOC.

Answered: 1 week ago