0% found this document useful (0 votes)
26 views2 pages

Tracing Problem2

The document contains the code for a Java program that: 1) Initializes an integer k to 109 and iterates through a do-while loop, dividing k by 3 or 2 depending on whether k is divisible by the iterator i. 2) Prints the output of k after each iteration of the do-while loop. 3) Contains nested for loops that print the values of i, j, and m when they meet certain conditions.

Uploaded by

aadi1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Tracing Problem2

The document contains the code for a Java program that: 1) Initializes an integer k to 109 and iterates through a do-while loop, dividing k by 3 or 2 depending on whether k is divisible by the iterator i. 2) Prints the output of k after each iteration of the do-while loop. 3) Contains nested for loops that print the values of i, j, and m when they meet certain conditions.

Uploaded by

aadi1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem Set:

import java.util.Scanner;
public class Tracing2
{
public static void main(String[] args)
{
int k = 109;
do
{
for(int i = 3; i < 9; i = i * 2)
{
if(k % i == 3)
k = k / 3;
else
k = k / 2;
}
System.out.println(k);
}while(k > 0);
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 2; j++)
{
for(int m = 0; m < i * 2; m++)
{
if(m == j && m == i)
{
System.out.println("i: " + i);
System.out.println("j: " + j);
System.out.println("m: " + m);
}
}
}
}
}
}
Output Memory box
27 K=109,54,27,13,6,3,1,0
6 I=3,6,12,3,6,12,3,6,12,3,6,12
1 I=0,1,2
0 J=0,1,2,0,1,2
I:1 M=0,0,0,0,1,2,0,1,2
J:1
M:1

You might also like