Answer the following about the loop below without compiling

Answer the following about the loop below without compiling and running it: a. What does the loop print b. Rewrite the loop as a for loop instead of a while loop. Write a for loop to print the numbers from 900 down to 4 that are multiples of 3, one number per line. A number is a factor of another if it evenly divides that number. for example, 3 is a factor of 12 because 12% 3 is0. Finish the method below to return the smallest factor of a that is large than k.

Solution

1)

a) the loop will print

10, 18, 26, 34, 42, 50, 58,

b) using for loop

int q;
for(q=10;q<=60;q+=8)
{
System.out.printf(\"%d, \", q);
}

2)

int q;
for(q=900;q>=4;q--)
{
if(q%3==0)
System.out.printf(\"%d\ \", q);
}

3)

public static int smallest(int n,int k)
{
for (int i = k+1; i*i<= n; i++)
{   
if (n % i == 0)
return i;
}
return n;
}

 Answer the following about the loop below without compiling and running it: a. What does the loop print b. Rewrite the loop as a for loop instead of a while lo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site