Public class Test { public static void main(String[] args) { int[][] values = { {9, 8, 7, 6, 5}, {7,
Question:
Answers
The program will output 777 and throw an error of .
Explanation:
The program declare an array called values. It is a multidimensional array. It then try to loops through the array and do some computation.
It has a nested for loop for going through the array.
For the first for-loop the length is 4.
During the computation in the inner loop; Exception thrown is: : Index 5 out of bounds for length 5
The exception is thrown because when i is 3, then values[i+2][j+2] will be values[5][5] and the length of values is 4.
Hi!
The correct answer is d. Neither (a) nor (b) is true.
Explanation:
First, you have to know what the scripts intend to do, and they are counting from 1 to 10 in both cases.
Table of results of class TestA at end of each iteration:
[j = 0, counter = 1]
[j = 10, counter = 2]
[j = 20, counter = 3]
[j = 30, counter = 4]
[j = 40, counter = 5]
[j = 50, counter = 6]
[j = 60, counter = 7]
[j = 70, counter = 8]
[j = 80, counter = 9]
[j = 90, counter = 10]
Table of results of class TestB at end of each iteration:
[j = 10, counter = 1]
[j = 9, counter = 2]
[j = 8, counter = 3]
[j = 7, counter = 4]
[j = 6, counter = 5]
[j = 5, counter = 6]
[j = 4, counter = 7]
[j = 3, counter = 8]
[j = 2, counter = 9]
[j = 1, counter = 10]
That's why a) and b) are false.
Maybe you want to know why using pre increments on class TestB doesn't affect the loop. The reason is that when enters in a loop, first checks the test condition and takes the decision if true or false, and last executes the incrementation step.
The answer is "Option d".
Explanation:
In the given code, two class "TestA and TestB" is defined, that calculates some values which can be described as follows:
In class "TestA", three integer variable "x, y, and counter" is declared, that initializes with a value, that is "2, 20, and 0", inside the class for loop is declare that uses variable j which starts from and ends when the value of j is less than 100, it will increment the value of counter variable by 1. In the class "TestB", an integer "counter" variable is initializes a value with 0, inside the class the for loop is used that uses variable j, which starts from 10, and ends when j is less than 0. in the loop it increments the value of "counter" variable by 1. that's why in this question except "option d" all were wrong.The J value is just the difference. In this case it is 2130 - 2123.5 = 6.5 Hz. This can get more difficult if a proton is split by more than one another proton, especially if the protons are not identical.
Explanation:
The solution code is written in Python:
i = 2 j = 3 itemp = i jtemp = j i = jtemp j = itempExplanation:
Given the i and j hold their respective values (e.g. 2 and 3) (Line 1-2). We can create another two more variables itemp and jtemp to hold the values of i and j (Line 3- 4). Next, we assign jtemp to i and itemp to j. This will enable the previous value of j assigned to i and previous value of i assigned to j (Line 5-6).