Ejemplo n.º 1
0
  public static void main(String[] args) {
    // partioning an array
    Scanner input = new Scanner(System.in);
    double[] inputDoubles;

    System.out.println("enter double cap");
    int size = input.nextInt();
    inputDoubles = new double[size];
    for (int i = 0; i < inputDoubles.length; i++) {
      // adds values to the array
      System.out.println("Enter double value for " + i + ":");

      inputDoubles[i] = input.nextDouble();
    }
    double[] result = partition(inputDoubles);
    for (int i = 0; i < result.length; i++) {
      // adds values to the array
      System.out.println("the value is " + result[i]);
    }

    // pt 2
    double totalTime = 0.0;
    for (int p = 0; p < 1000; p++) {
      double[] random100 = new double[100000];
      double time = System.currentTimeMillis();
      for (int i = 0; i < random100.length; i++) {

        int rand = (int) (100000 * Math.random()) + 1;
        random100[i] = rand;
      }

      timelasped(random100);
      double endTime = System.currentTimeMillis();
      totalTime += (endTime - time);
      // System.out.println("the time to run this alogrthim is: " + (endTime - time));
    }

    System.out.println("the average is " + totalTime / 1000);
  }