Could someone show me a code demo of a 1D array that has fixed int's and is then stored in a result using a loop?
-
I have this int[] anArray = { 1,2,3,4,5,6,7,8,9}; int total = 0; for(int x = 0; x < anArray.length; x++){ total += anArray[x]; } System.out.println(anArray[total]); It compiles, but does run. I just want it to print the numbers in my array, using a loop. Suggestions?
-
Answer:
Well if you want to print the numbers in the array you must do System.out.println(anArray[x]) each time, and if you want to print the total sum then you must print System.out.println(total).
Julián Solórzano at Quora Visit the source
Related Q & A:
- How to convert a char array into an int in C++?Best solution by Stack Overflow
- How to create a loop for below code?Best solution by WordPress
- What's the best way to get a job in a restaurant?Best solution by Yahoo! Answers
- How to make a font using a png image?Best solution by Super User
- If someone calls within usa using a phone card does it show their number on caller id or something else?Best solution by 800notes.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.