如何计算完成程序所需步骤的输出

时间:2018-07-22 15:21:12

标签: java random hash

嗨,我有这个程序,当我运行10次时,我想计算并打印完成该程序所需的全部步骤。 (计算控制台总行数)

任何建议都值得赞赏

哈希表的代码:

public class HashFunction {

String[] theArray;
int arraySize;
int itemsInArray = 0;
    int K = 0;

/**
 *
 * @param args
 */
public static void main(String[] args) {


HashFunction theFunc = new HashFunction(101);

String[] elementsToAdd2 = new String[101];

for (int i = 0; i <= 100; i++) {
elementsToAdd2[i] = Integer.toString(RandomNumbers.getRandomNumberInRange(0, 15024267));
}



    theFunc.hashFunction2(elementsToAdd2, theFunc.theArray);

}


public void hashFunction2(String[] stringsForArray, String[] theArray) {

    for (int n = 0; n < stringsForArray.length; n++) {

        String newElementVal = stringsForArray[n];

        // Create an index to store the value in by taking
        // the modulus

        int arrayIndex = Integer.parseInt(newElementVal) % 101;

        System.out.println("P" + arrayIndex + " " + "I" + newElementVal + "@" + arrayIndex );

        // Cycle through the array until we find an empty space

        while (theArray[arrayIndex] != "-1") {

            ++arrayIndex;

            System.out.println( "P" + arrayIndex);

            // If we get to the end of the bucket go back to index 0

            arrayIndex %= arraySize;

        }

        theArray[arrayIndex] = newElementVal;

    }

}

HashFunction(int size) {

    arraySize = size;

    theArray = new String[size];

    Arrays.fill(theArray, "-1");

}

}

运行该类10次的程序:

public class RunTenTimes
    {
public static void main(String[] args)
  {
      for(int i=1; i<=10; i++)
          HashFunction.main(args); 
  }
}

我应该在主类中还是在RunTenTimes类中添加代码?

0 个答案:

没有答案