标签:参数 click i+1 ring main static demo imp pac
1 package pack; 2 import java.util.*; 3 4 public class demo_1 { 5 static int r,n; 6 static int a[]=new int [100]; 7 static int b[]=new int[100]; 8 static void f(int point,int picked) { 9 if(picked==r) { 10 for(int i=0;i<r;i++) 11 System.out.print(b[i]+" "); 12 System.out.println(); 13 return ; 14 } 15 for(int i=point;i<n;i++) { 16 b[picked]=a[i]; 17 f(i+1,picked +1); 18 } 19 } 20 21 public static void main(String[] args) { 22 Scanner in = new Scanner(System.in); 23 System.out.print("请输入N的值:"); 24 n=in.nextInt(); 25 System.out.println("请输入数组的"+n+"个值:"); 26 for(int i=0;i<n;i++) 27 a[i]=in.nextInt(); 28 29 System.out.print("请输入R的值"); 30 r=in.nextInt(); 31 f(0,0); 32 33 } 34 }
在n个任意不相同的数中,输出r个数的组合,并且n和r由键盘输入。
标签:参数 click i+1 ring main static demo imp pac
原文地址:https://www.cnblogs.com/qq396986862/p/10729464.html