## Problem:

Given start and end numbers, return a new array containing the sequence of integers from start up to but not including end, so start=5 and end=10 yields {5, 6, 7, 8, 9}. The end number will be greater or equal to the start number. Note that a length-0 array is valid. (See also: FizzBuzz Code)

fizzArray3(5, 10) → {5, 6, 7, 8, 9}
fizzArray3(11, 18) → {11, 12, 13, 14, 15, 16, 17}
fizzArray3(1, 3) → {1, 2}

## Solution:

public int[] fizzArray3(int start, int end) {
int n = end - start;
int[] result = new int[n];

for (int i = 0; i < n; i++)
result[i] = start++;
return result;
}

#### 13 comments :

1. int dif = end-start;
int[] erg = new int[dif];

for(int i=0; i < dif; i++){
erg[i] = start+i;
}
return erg;

2. public int[] fizzArray3(int start, int end) {
int[] newArray = new int[end-start];
int count = 0;
for(int i=start; i<end; i++){
newArray[count] = i;
count++;
}
return newArray;
}

3. public int[] fizzArray3(int start, int end) {
int[] arr = new int[end-start];
for (int i=start; i<end; i++){
//if (i==start)
arr[i-start]=i;
}
return arr;
}

4. public int[] fizzArray3(int start, int end) {
int[] newArray = new int[end - start];
int addOn = 0;

for(int i = 0; i < end - start; i++) {
newArray[i] = start + addOn;
}
return newArray;
}

5. public int[] fizzArray3(int start, int end) {

int[] fizzArray = new int[end - start];

for (int i = 0, j = start; j < end; i++, j++) {

fizzArray[i] = j;
}
return fizzArray;

6. public int[] fizzArray3(int start, int end) {
if(start >= end) return new int[0];

int[] out = new int[end - start];
for(int i = 0; i < out.length; i++) {
out[i] = start + i;
}
return out;
}

7. public int[] fizzArray3(int start, int end) {
int[] q=new int[end-start];
int a=end-start;
for(int i=0;i<a;i++){
q[i]=start++;
}return q;
}

8. public int[] fizzArray3(int start, int end) {
int diff = end-start;
int[] result = new int[diff];
for(int i=0; i<diff; i++)
{
result[i] = start;
start++;
}return result;
}

9. public int[] fizzArray3(int start, int end) {
int size=end-start;
int a[]=new int[(size)];

for(int i=0;i<size;i++){
a[i]=start++;
}
return a;
}

10. int len= end-start;

int [] newArray= new int [len];

for (int i=0; i<len ; i++){
newArray [i] = start+i;
}

return newArray;

11. With Java Stream

public int[] fizzArray3(int start, int end) {
return java.util.stream.IntStream.range(start, end).toArray();
}

12. public int[] fizzArray3(int start, int end) {
int s = end - start;
int[] nums = new int[s];

for(int i = start,j=0; i < end; i++,j++){
nums[j] += i;
}
return nums;
}

13. public int[] fizzArray3(int start, int end) {

int[] b=new int[end-start];
for(int i=start,j=0;i<end;i++,j++){
b[j]=i;
}
return b;

}