以下 public static void main(String[] args) {
// TODO code application logic here
System.out.println("Please enter the size of the array: ");
Scanner input1 = new Scanner(System.in);
int numBits = input1.nextInt();
Scanner input2 = new Scanner(System.in);
System.out.println("Please enter size of radix: ");
int radixNum = input2.nextInt();
getBits(radixNum);
ArrayList<Integer> sortIt = new ArrayList<Integer>();
radSort(sortIt, radixNum, numBits);
System.out.println(sortIt.toString());
}
private static int getBits(int radixNum) {
double lognum = Math.log(10000);
double logbase = Math.log(radixNum);
int numBits = (int) Math.floor((lognum / logbase) + 1);
System.out.println("Bits " + numBits);
return numBits;
}
/**
* Sorts the array in a radix sort where the radix is decided by the user
*
* @param sortIt
* @param radixNum
*/
private static ArrayList radSort(ArrayList<Integer> sortIt, int radixNum, int numBits) {
ArrayList<ArrayList<Integer>> bucketStorage = new ArrayList();
ArrayList<Integer> temp;
temp = sortIt;
int tempNumb;
for (int i = 0; i < radixNum; i++) {
ArrayList<Integer> bucket = new ArrayList<>();
bucketStorage.add(bucket);
}
for (int j = 0; j < numBits; j++) {
while (!temp.isEmpty()) {
tempNumb = temp.remove(0);
bucketStorage.get(getBitNumber(tempNumb, j, radixNum)).add(tempNumb);
}
for (int m = 0; m < bucketStorage.size(); m++) {
for (int n = 0; n < bucketStorage.get(m).size(); n++) {
temp.add(bucketStorage.get(m).get(n));
}
bucketStorage.get(m).clear();
}
}
return temp;
}
private static int getBitNumber(int a, int b, int R) {
double expNum;
int entry;
expNum = Math.pow(R, b);
entry = (int) Math.floor(a / expNum) % R;
return entry;
}
}
是对的。但我不明白为什么它使用额外的行public void function(int number,for(int b;b>number;b++){int param2, int param3,int param4,int param5,int param6})
{ //start of body
for(int b;b>number;b++)
{
object[b].setter(param2)
object[b].setter(param3)
object[b].setter(param4)
object[b].setter(param5)
object[b].setter(param6)
}
}
? “func
”的含义是什么?
有人有任何线索吗?
sumOf ( )
答案 0 :(得分:2)
第sumOf()
行证明你可以完全没有参数地调用该函数。
答案 1 :(得分:0)
sumOf
的课程都是&#34;不必要的&#34;对于功能本身。它只显示了用法。
Int...
是一个可变参数
可变参数接受零个或多个指定类型的值。 https://developer.apple.com/library/watchos/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html