0

Hi! I'm new to Java.
I need to make an array like:
int b[] = {0,1,2,3,4,5,6,7,8,9};
Is it possible to use a loop to generate an array like that?
I don't know if I'm asking the right question, so I will try to explain it:

class test0{
	int a=0;
	public test0(){
		int b[]={
			for(int i=0;i<10;i++){
				a++;
			}
		};
	}
	public static void main(String args[]){
		new test0();
	}
}

Thanks a lot in advance.

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by aveltium
0

It is very possible to create an array that way. You know the array will be of size 10. so you can start off by declaring the the array as that size.
Then run the loop with the counter 'i' you have chosen above and you can set each individual element 'b = i'

Hope that helps

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.