public class Test { /*创建类*/public static void main(String[] args) {System.out.println(dg(100));}static int dg(int i) { /*定义变量 */int sum;if (i == 1) /*假设条件*/return 1;elsesum = i + dg(i - 1); /*1~100的和的表达式*/retur...
成都创新互联公司网站建设公司一直秉承“诚信做人,踏实做事”的原则,不欺瞒客户,是我们最起码的底线! 以服务为基础,以质量求生存,以技术求发展,成交一个客户多一个朋友!专注中小微企业官网定制,成都网站设计、成都网站制作,塑造企业网络形象打造互联网企业效应。
public class MyClass {
public static void main(String[] args) {
System.out.println(" result count:" + method(6, 3));
}
public static int method(int n, int k) {
ListListInteger list = new ArrayList();
for (int i = 0; i k; i++) {
if (i == 0) {
for (int j = 1; j n; j++) {
ListInteger li = new ArrayList();
li.add(j);
list.add(li);
}
continue;
}
ListListInteger listNew = new ArrayList();
for (ListInteger integers : list) {
for (int j = integers.get(integers.size() - 1); j n; j++) {
ListInteger li = new ArrayList();
li.addAll(integers);
li.add(j);
listNew.add(li);
if (i + 1 == k) {
int res = 0;
for (Integer integer : li) {
res += integer;
}
if (res != n) {
listNew.remove(li);
}
}
}
}
list.clear();
list.addAll(listNew);
}
for (ListInteger integers : list) {
for (Integer integer : integers) {
System.out.print(integer + "\t");
}
System.out.println();
}
return list.size();
}
}
import java.util.Arrays;
public class Test {
public static void getCha(int [] a,int []b){
int min =Integer.MAX_VALUE;
int sss=0;
int kkk = 0;
int c = 0;
int d = 0;
for (int i = 0; i a.length; i++) {
for (int j = 0; j b.length; j++) {
int temp = Math.abs(a[i]-b[j]);
if(tempmin){
min = temp;
sss = a[i];
kkk = b[j];
c=i;
d=j;
}
}
}
System.out.println("最大差距:"+min+"数组A["+c+"]"+sss+"数组B["+d+"]"+kkk);
}
public static void main(String[] args) {
int []a = new int[8];
int []b = new int[12];
for (int i = 0; i a.length; i++) {
a[i] = (int)( Math.random()*100);
}
System.out.println(Arrays.toString(a));;
for (int i = 0; i b.length; i++) {
b[i] = (int) (Math.random()*100);
}
System.out.println(Arrays.toString(b));
getCha(a,b);
}
}