# Arrays, filling an array with set of values

• 12-30-2012, 07:48 PM
FOX427
Arrays, filling an array with set of values
Hi All!

I am having little issue with my code here:

Code:

```/**  * This program fills an array "squares" with the values to be squared at the end, for example, output should be  1 4 9 16 25 36 49 64 81 100  * @author FOX  *  */ public class R7d7 {         /**         * @param args         */         private int i;                 public void fillSquare()         {                 int[] squares = new int[10];                                 for (int i = 0; i<squares.length; i++);                 {                         squares[i]=i*i;                         System.out.println(squares[i]);                 }                                         }         public static void main(String[] args) {                 // TODO Auto-generated method stub                 R7d7 test = new R7d7();                                 test.fillSquare();         } }```
the program gives me a single value(that is 0) instead of giving a list of squares. I don't know where I got wrong but will be very thankful if someone helps me, thanks!
• 12-30-2012, 08:12 PM
eRaaaa
Re: Arrays, filling an array with set of values
for (int i = 0; i<squares.length; i++); <- you have to delete this semikolon!
Otherwise your loop looks similar to
Code:

```        for (int i = 0; i<squares.length; i++)         {                     }```
->
Code:

```        for (int i = 0; i<squares.length; i++)         {                     }         {             squares[i]=i*i;             System.out.println(squares[i]);         }```
no printing within loop, one single print after loop!
• 12-30-2012, 09:12 PM
FOX427
Re: Arrays, filling an array with set of values
haha! can't believe that I made such an elementary mistake! thanks you ! :))
• 12-30-2012, 09:19 PM
JosAH
Re: Arrays, filling an array with set of values
It's completely off topic but I like the comments in your code (they're totally incorrect); better remove your comments instead of leaving in incorrect comments.

kind regards,

Jos
• 12-30-2012, 09:35 PM
FOX427
Re: Arrays, filling an array with set of values
got it!