问题描述
我需要编写一个程序,以特定格式打印数组的所有子数组。
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,3)
我能够使用两个循环获取所有子数组,但无法按此特定顺序生成输出。我正在使用 Java 进行编码。 我的代码如下:- 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);
}
这段代码给出了所有可能的子数组,但不是所有可以从数组形成的传染性子数组组合。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)