There's an array say [1,2,4,5,1]. I need to print all the contiguous sub-arrays from this.
Input: [1,2,4,5,1]
Output:
1
1,2
1,2,4
1,2,4,5
1,2,4,5,1
2
2,4
2,4,5
2,4,5,1
4
4,5
4,5,1
5
5,1
1
I tried but couldn't get the complete series.
//items is the main array
for(int i = 0; i < items.length; i++) {
int num = 0;
for(int j = 0; j < items.length - i; j++) {
for(int k = i; k < j; k++) {
System.out.print(items[k]);
}
System.out.println();
}
}