12 Replies Latest reply on May 3, 2013 2:03 PM by foot_

# OAC Study Guide - Programmer I (question)

For the following code block, found on page 257 of the OCA JSE7 Guide Question #7, an IDE alert shows up "the value of the local variable sum is not used", however the answer is 15. What are the assumptions not given, specifically related to sum?
``````          int[][] square = new int[3][3];
for(int i=0;i<3;i++){
square[i] =5;
}
int sum = 0;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++){
sum +=square[i][j];
}

}Edited by: 1003731 on May 2, 2013 8:31 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ``````
• ###### 1. Re: OAC Study Guide - Programmer I (question)
1003731 wrote:
How are you checking that? The only thing the warning means is that you have a variable (sum) which you never really do anything with, at least not in the code that you posted. The warning will already go away if you do a System.out.println() on it.
``````int[][] square = new int[3][3];
for(int i=0;i<3;i++){
square[i] =5;
}
int sum = 0;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++){
sum +=square[i][j];
}
}
System.out.println("Sum: " + sum);``````
A warning is not necessarily a problem, it is just an indicator that the IDE gives you that something might not be as you wanted it to be, to help you to find faults in your code. Not doing anything with a variable is usually an indication of a mistake.

(EDIT: I fixed the copied code which was broken due to the forum eating up formatting tags)
• ###### 2. Re: OAC Study Guide - Programmer I (question)

Yes, I had left out a print test. So now I see and understand what is being asked in the question.

Overall, I am both learning and preparing for the OCA exam. I realize in preparation material there will be things thrown at me that I need to sort out - fact from fiction. I am learning as much as I am able to. I wish I could grasp it better and better. I have that desire.

Edited by: 1003731 on May 2, 2013 8:32 AM
• ###### 3. Re: OAC Study Guide - Programmer I (question)
1003731 wrote:

Yes, I had left out a print test. So now I see and understand what is being asked in the question.

So, I noticed that you left out the three instances of , but do not know why. Are they extraneous to what was originally being asked?

Overall, I am both learning and preparing for the OCA exam. I realize in preparation material there will be things thrown at me that I need to sort out - fact from fiction. Basically, I just want to be able to capitalize on all the time and money I have already dedicated to Java already. I should be able to get a career job - entry level at the least.
The [ i ] were "left out" because you didn't use code tags in your first post. Thus, the [ i ] (without spaces) was interpreted as "start italics", just as it was in your second post. Yes, the [ i ] is very much needed in the code. gimbal2 just copied your code from your post as it shows up when you don't use code tags---the [ i ] can't be seen when it is interpreted as "start italics".
• ###### 4. Re: OAC Study Guide - Programmer I (question)
Thank you. This is helpful, and I apologize.

I did not notice code tag options in the editor. Would you be able to reference this information, please?

Edited by: 1003731 on May 2, 2013 8:27 AM
• ###### 5. Re: OAC Study Guide - Programmer I (question)
oops, I fixed my copy of the code. In the future use \
`````` tags when posting code to prevent the forum from eating up formatting tags and to have it printed out prettily like you can see in my post, like so:

\``````
yourcodehere
\
``But what I say may not be relevant anymore soon as the forum is getting a major upgrade.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ``
• ###### 6. Re: OAC Study Guide - Programmer I (question)
1003731 wrote:
Thank you. This is helpful, and I apologize.

I did not notice code tag options in the editor. Would you be able to reference this information, please?

Edited by: 1003731 on May 2, 2013 8:27 AM
The description on how to format your code is given in the Forum FAQ document:
https://forums.oracle.com/forums/help.jspa

There is a link to it at the top corner of every forum page.

• ###### 7. Re: OAC Study Guide - Programmer I (question)
I just found it prior to your post. Thank you. Thank you. I am sorry for all this.
• ###### 8. Re: OAC Study Guide - Programmer I (question)
Thank you to you all. I appreciate this. I am learning. While I can change me. I cannot change you. Discussion boards are easy places to lash out. I can take it. It does not deter me.
• ###### 9. Re: OAC Study Guide - Programmer I (question)
1003731 wrote:
Thank you to you all. I appreciate this. I am learning. While I can change me. I cannot change you. Discussion boards are easy places to lash out. I can take it. It does not deter me.
Do you always feel attacked? You got nothing but help, nobody is lashing out at you.