I need to write a program to print all sub arrays of an array in a particular format.
Example-
I/o:
n = 3
A = (1,2,3) where n is the size of the array and A is the array itself.
O/p:
(1),(2),(3)
(1),(2,3)
(1,2),(3)
(1,2,3)
I am able to get all subarrays using two loops but cannot produce the output in this particular order.I am coding in Java. My code goes is as follows:- a[]→integer Array of n elements
for(int i=0;i<a.length;i++){
String s = "";
for(int j=i;j<a.length;j++){
s = s + a[j] + " ";
System.out.println(s);
}
This code gives all possible sub arrays but not all contagious sub array combination that can be formed from an array.