给定两个整数数组(第一个是数组 A,第二个是数组 B),在数组 A 中取 A[i],数组 B 中取 B[j],A[i] 和 B[j]两者的差越小越好(|A[i] - B[j]|)。返回最小差。

来源:互联网 发布:金融数据分析师招聘 编辑:程序博客网 时间:2024/06/04 17:47

public static void main(String[] args) {

int[] AArray = { 3, 4, 6, 7 };

int[] BArray = { 19, 10, 49, 10, 323, 131, 341, 555 };

int tempB = 0;

Object[] CArray =new Object[] {};

List<Integer> c =new ArrayList<Integer>();

int temp = 0;

for (inti = 0; i < AArray.length;i++) {

for (intj = 0; j < BArray.length;j++) {

temp =AArray[i] - BArray[j];

if (temp < 0) {

temp =temp * (-1);

}

if(i==0 &&j==0){

tempB =temp;

}

if(tempB>temp){

tempB =temp;

}

}

}

System.out.println("====最小的值====" +tempB);

}

0 0
原创粉丝点击