我有下面的代碼。當從文本文件中輸入時,不會比較大小
import java.io.File;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
public class Scalar {
public static void main(String args[]) throws Exception {
Scanner sc=new Scanner(new File("D:/GC/Scalar/A-small.in"));
int testcases=Integer.parseInt(sc.next());
System.out.println(testcases);
ArrayList<BigInteger> a=new ArrayList<BigInteger>();
ArrayList<BigInteger> b=new ArrayList<BigInteger>();
for(int j=0;j<2;j++){
int size=Integer.parseInt(sc.next());
System.out.println(size);
for(int i=0;i<size;i++)
{
a.add(sc.nextBigInteger());
}
for(int i=0;i<size;i++)
{
b.add(sc.nextBigInteger());
}
Collections.sort(a);
System.out.println(a.size());
System.out.println(a);
Collections.sort(b,Collections.reverseOrder());
System.out.println(b);
BigInteger sum;
for(int i=0;i<a.size();i++){
sum=a.get(i).multiply(b.get(i));
sum=sum.add(sum);
}
}
}
}
和下面的內容在一個文本文件中。
1000
3
1 -5 3
-2 1 4
5
5 4 3 1 2
1 1 0 1 0
7
677 463 -569 516 401 -998 882
890 588 959 909 948 -617 -655
8
-912 937 167 366 -222 -397 190 -216
354
這裏我試圖所述第一陣列和以相反的順序在第二排序,然後做和與積,在這裏,我只用了2例,在1000中輸入以上是測試用例總數,和單個數字行表示數組的大小,並且在我的程序中要確保數組的大小與給定的大小相匹配,我打印大小,在第一種情況下,輸入大小爲3,我得到它正確,但在第二種情況下,輸入的大小是5,但是我將它作爲數組的大小,下面是我得到的輸出。
1000
3
3
[-5, 1, 3]
[4, 1, -2]
5
8
[-5, 1, 1, 2, 3, 3, 4, 5]
[4, 1, 1, 1, 1, 0, 0, -2]
請讓我知道我在哪裏錯了。
感謝