Maneesh Godbole wrote:Why are you even using the loop?
You can access the elements directly by fields[6],fields[7]...fields[n] right?
Maneesh Godbole wrote:So what you are trying to do is (in pseudo code)
1) Ignore 1st 6
2) Take next 4 and process
3) Take next 4 and process
Hint: Array elements can be accessed using an index(which starts with 0)
Harsha Smith wrote:Field check not initialized
Field declared on line 10
Campbell Ritchie wrote:You are arguing from the particular to the general; that is not valid. You need to go from the general to the particular.
Let’s work out its weakest-precondition transformer effect, to establish z = y, which means the value of y at the end of the program.
[y = y + x; y = y + x]z = y ≡ by the Sequence Rule
[y = y + x][y = y + x]z = y ≡ by the assignment rule on the right
[y = y + x]z = y 〈y \ x + y〉 ≡ by substitution
[y = y + x]z = x + y ≡ by the assignment rule on the left
z = x + y 〈y \ x + y〉 ≡ by substitution
z = x + y + y ≡ by algebra
z = x + 2y QED
You can now substitute 1 for x and 1 for y and get 3.
Harsha Smith wrote:
* Using interface as a type. What is the whole
point of this, why is this legal? Does it
make any sense?*/
Haven't you read the chapters "Inheritance" and "Polymorphism" yet?
Campbell Ritchie wrote:I would prefer to see the method called launchRocket().
Harsha Smith wrote:second problem, say the value of x = 1 and y =1
now y = y+x // y =2
again y = y+x// 2 +1
System.out.println(y)//prints 3
similary y = y+2*x //1+2*1 = 3
System.out.println(y)//prints 3
Got it?
Campbell Ritchie wrote:Where on earth did you find those questions? They look designed to confuse. You would have to go through the execution of the code with a pencil and paper, and you can write down the values after each operation. With the two nested loops, you can tell that the loops are executed n × m times, but only if both numbers are positive; if either number is negative, you get an output of 0.