java - 如何计算完成程序所需步骤的输出
问题描述
嗨,我有这个程序,我想在运行 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 类中添加代码?
解决方案
推荐阅读
- mongodb - 如何在数组(一个文档)中查找重复元素?
- swift - 在循环中寻址多个 IBOutlet
- mongodb - 您可以更新 MongoDB 中的集合并删除一个字段上的第一个/最后一个字符吗?
- javascript - 如何修复meteor.js中的“模板助手中的异常:ReferenceError:未定义Todos”错误
- stm32 - 无法将 PC15 用作 stm32f030rc 上的 GPIO 输入
- c# - 如何让 WebBrowser 导航到不受信任的站点?
- javascript - 如何解决运行测试时找不到函数的代码覆盖问题?
- java - java.lang.IllegalArgumentException:名为 [A] 和 [A] 的 servlet 都映射到不允许的 url 模式 [/testurl]
- javascript - 什么可能导致 TensorFlow.js 模型以不可读的格式生成输出?
- varnish - 我想使用清漆缓存 410 页面