Monday, January 9, 2012
What is the output of the java program?
The function Coyle contains a while loop that loops n times (k starts at 1, and increments by one each loop). This means that since you are ping in x, which equals 64, it will loop 64 times. s starts at 0, and has n added to it for each p through the loop. This means that it will add 64 to the variable s 64 times. The final value of s will therefore be the same as 64 *64 and this is the value that is returned. Going back up to your System.out.println statement, this value is then multiplied by 10, which means that the program will display 64 * 64 *10, or "sum= 40960."
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment