Java 如何找到数组的所有连续子数组组合并打印它

Java 如何找到数组的所有连续子数组组合并打印它,java,arrays,dynamic-programming,sub-array,Java,Arrays,Dynamic Programming,Sub Array,我需要编写一个程序以特定格式打印数组的所有子数组 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) 我可以使用两个循环获得所有子数组,但不能以这种特定的顺序生成输出。 我的代码如下:- a[]→n个元素的整数数组 for(int i=0;i<a.length;i+

我需要编写一个程序以特定格式打印数组的所有子数组

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)
我可以使用两个循环获得所有子数组,但不能以这种特定的顺序生成输出。 我的代码如下:- a[]→n个元素的整数数组

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);
}

for(inti=0;i如果没有递归,这是一件很难的事情。即使递归对于这个方法来说也是很难的,因为你必须在递归方法内部循环,这是很不寻常的

主类{
静态void打印组(int[]a,int start,字符串输出){
输出+=”(“+a[启动];
对于(int i=start+1;i
这将产生:

(1)、(2)、(3)、(4)
(1),(2),(3,4)
(1),(2,3),(4)
(1),(2,3,4)
(1,2),(3),(4)
(1,2),(3,4)
(1,2,3),(4)
(1,2,3,4)

请共享您的代码。共享我的代码。