C#
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication4 7 { 8 class Program 9 {10 static void Main(string[] args)11 {12 List originalList = new List ();13 for (int i = 1; i <= 5; i++)14 {15 originalList.Add(i);16 }17 Console.Write("源数组:");18 foreach (int item in originalList)19 {20 Console.Write(item + " ");21 }22 Console.WriteLine();23 List> resultList = new List
>();24 // 每一次由底至上地上升25 for (int i = 0; i < originalList.Count; i++)26 {27 List subList = new List ();28 for (int j = 0; j < originalList.Count; j++)29 {30 if (j != i)31 {32 subList.Add(originalList[j]);33 }34 }35 resultList.Add(subList);36 }37 for (int i = 0; i < resultList.Count; i++)38 {39 List subList = resultList[i];40 Console.Write("子数组" + (i + 1) + ":");41 for (int j = 0; j < subList.Count; j++)42 {43 Console.Write(subList[j] + " ");44 }45 Console.WriteLine();46 }47 Console.WriteLine("子数组的数量:" + resultList.Count);48 Console.ReadKey();49 }50 }51 }
JS
1 2 3 4 56 7 8 9 39 40
Java
1 import java.util.ArrayList; 2 import java.util.List; 3 4 public class Test { 5 6 public static void main(String[] args) { 7 int score[] = { 1,2,3,4 }; 8 List
>list=new ArrayList
>(); 9 // 每一次由底至上地上升10 for (int i = 0; i < score.length; i++) {11 List array=new ArrayList ();12 for (int j = 0; j < score.length; j++) {13 if (j != i) {14 array.add(score[j] );15 }16 }17 list.add(array);18 }19 for (List l : list) {20 System.out.println(l);21 }22 }23 }