Professional Documents
Culture Documents
ANSWERS
Output: Value : b4
Program Tracing/Iteration Steps Executed. Show the step-by-step execution based on the elements or
components of the loop. Add more rows/columns, if necessary, for the given table below.
ANSWERS
Program Tracing/Iteration Steps Executed. Show the step-by-step execution of the first loop in the
program, based on the elements or components of the loop. Add more rows/columns, if necessary, for the
given table below.
Output:
for (int i = dblArr.length - 1; i >= 0; i--)
{
System.out.println("Value : " + dblArr[i]); //highlighted on the table but the variable i
} starts with 4 then decrement
Array Exercises – Program Tracing & Coding
ANSWERS
Output: 1: 0.5
2: 2.0
3: 4.5
4: 8.0
5: 12.5
Program Tracing/Iteration Steps Executed. Show the step-by-step execution of the first loop in the
program, based on the elements or components of the loop. Add more rows/columns, if necessary, for the
given table below.
Output:
for (int i = 0; i < intArr.length; i++)
{
System.out.println(intArr[i] + ": " + dblArr[i]); //highlighted on the table
}
Array Exercises – Program Tracing & Coding
ANSWERS
Output: Value : 1
Value : 4
Value : 7
Value : 10
Program Tracing/Iteration Steps Executed. Show the step-by-step execution based on the elements or
components of the loop. Add more rows/columns, if necessary, for the given table below.
Output:
5. Create a for-loop structure that will display each index and the element stored (of the corresponding
index) in the array named strArr. In the display, separate the index and the corresponding
element value by a colon (:). Each entry should be displayed on a separate line. Do not hardcode
the length of the array in any way.
ANSWER:
public class MainProgram {
public static void main(String [] args) {
int [] strArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int i = 0; i < strArr.length; i ++)
{
System.out.println(i + " : " + strArr [i]);
}
}
}