This discussion is archived
12 Replies Latest reply: May 3, 2013 7:03 AM by foot_

# OAC Study Guide - Programmer I (question)

Currently Being Moderated
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)
Currently Being Moderated
1003731 wrote:
however the answer is 15.
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)
Currently Being Moderated
Thank you for reply.

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)
Currently Being Moderated
1003731 wrote:
Thank you for reply.

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)
Currently Being Moderated
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)
Currently Being Moderated
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)
Currently Being Moderated
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.

That document, as well as the forum site's Terms Of Use (linked at the BOTTOM of every page) are what you should have read immediately after joining.
• ###### 7. Re: OAC Study Guide - Programmer I (question)
Currently Being Moderated
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)
Currently Being Moderated
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)
Currently Being Moderated
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.
• ###### 10. Re: OAC Study Guide - Programmer I (question)
Currently Being Moderated
Yes. Good question. Anyone who has a job is. Anyone who does not have a job is. I had a job, was offered relocation; did not make sense to wife and I so did not take the job. As a result my position was eliminated. Now I do not have a job. It is a lean competitive workplace. However, I am blessed. I am thankful. I do prosper and I do succeed. There is no doubt about that.

David
• ###### 11. Re: OAC Study Guide - Programmer I (question)
Currently Being Moderated
foot_ wrote:
Discussion boards are easy places to lash out. I can take it. It does not deter me.
You should probably stop being a martyr. But if you're learning Java in order to get a job, it'll take quite a while to learn the ropes.
• ###### 12. Re: OAC Study Guide - Programmer I (question)
Currently Being Moderated
If you were to do it all over again, what would you do differently in order to shorten the process?

Are there pivotal concepts, paradigm shifts, moments of enlightenment that were key?

#### Legend

• Correct Answers - 10 points
• Helpful Answers - 5 points