This site requires JavaScript, please enable it in your browser!
Greenfoot back
Leenza
Leenza wrote ...

2015/4/15

Arrays

Leenza Leenza

2015/4/15

#
I want to make an array the contains all the integers 0 to 100. However, the only way I know how to make an array is:
int [] numArray= {0,1,2,3,4,5,6,7,8};
I don't want to type every number from 0 to 100, so I was wondering if there was a shortcut?
danpost danpost

2015/4/15

#
There is a shortcut. However, you will not be able to assign the values while declaring the array.
// declare and initialize the array with the following
int[] numArray = new int[101];
// then in the class constructor assign the values
for (int n=0; n<101; n++) numArray[n] = n;
Leenza Leenza

2015/4/15

#
Thanks for the quick response!!
You need to login to post a reply.