Given a non negative number n where (n>0), create and return a new string array of length n, containing the strings "0", "1" "2" .. Through n-1.
Answers
Answered by
0
n1 is a String which has the value "n" in it.
whereas n is a variable whose value varies from 0 to num - 1.
SO you might want to assign n instead of n1.
int n=0; String[] arr=new String[num]; for(int i = 0; i < num; i++){ arr[i]= n; n = n + 1; }
If you look closely, n and i have the same value, you don't need n too.
String[] arr=new String[num]; for(int i = 0; i < num; i++){ arr[i] = i; }
whereas n is a variable whose value varies from 0 to num - 1.
SO you might want to assign n instead of n1.
int n=0; String[] arr=new String[num]; for(int i = 0; i < num; i++){ arr[i]= n; n = n + 1; }
If you look closely, n and i have the same value, you don't need n too.
String[] arr=new String[num]; for(int i = 0; i < num; i++){ arr[i] = i; }
Similar questions