Search:

Type: Posts; User: theoriginalanomaly

Search: Search took 0.10 seconds.

  1. Replies
    17
    Views
    1,855

    Re: How To Use Linear Search

    That is not correct. The initial values of the array are all 0's so it checks all 10 numbers to see if they match. Here is an example output after the first roll.


    ----------------
    d1: 4
    d2: 6...
  2. Replies
    17
    Views
    1,855

    Re: How To Use Linear Search

    You are calling the index "System.out.println("index is: " + sumArray[i]);" that is the value you want i. Also, you have the check running everytime you fill the index so it is checking a bunch of...
  3. Replies
    17
    Views
    1,855

    Re: How To Use Linear Search

    instead of break, you could break out of the first loop by i = sumArray.length -1;

    --- Update ---

    Now that I think about it. It would be more efficient to make the second for loop



    for...
  4. Replies
    17
    Views
    1,855

    Re: How To Use Linear Search

    for (int i = 0; i < sumArray.length; i++){
    for (int j = sumArray.length -1; j >= 0; j--){
    if (( i != j) && (sumArray[i] == sumArray[j])){
    System.out.println("You win!");
    ...
Results 1 to 4 of 4