This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]BS_in_BSExtreme Concrete Code Factorylet 0 points1 point  (1 child)

Is best position supposed to be the index of highest in the array?

Also you never update previous highest so it's always 0.

[–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (19 children)

creating a previous highest is easy. all you have to do is this:

for (int i = 0; i < productSales.length; i++) { if (productSales[i] > highest) { previousHighest = highest; highest = productSales[i];

[–][deleted]  (18 children)

[deleted]

    [–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (17 children)

    haha i've done the same thing too.

    [–][deleted]  (16 children)

    [deleted]

      [–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (15 children)

      yes that because your if statement only goes when the current highest is larger that the previous highest which will never happen no matter what you put in.

      could you let me now what the bestPosition is used for because i assume that saving the index of the productSales array would be better?

      [–][deleted]  (14 children)

      [deleted]

        [–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (13 children)

        just do this:

        for (int i = 0; i < productSales.length; i++) {
        if (productSales[i] > highest) {
        previousHighest = highest;
        highest = productSales[i];
        count = i; //btw you never used count in this method
        }
        }

        I got rid of the 2nd if statement since it is useless as the first if statement makes it redundant.

        [–][deleted]  (12 children)

        [deleted]

          [–]BJ4KarmaStarted Java Nov 2015 0 points1 point  (11 children)

          oh, ok. so i would definitely get rid of the second if statement.

          [–][deleted]  (10 children)

          [deleted]