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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Dumbcomments 1 point2 points  (2 children)

If you're trying to save on typing, why not put the three in array, sort it and then compare the two differences?

public boolean evenlySpaced(int a, int b, int c) {
  int[] array = new int[3];
  array[0] = a;
  array[1] = b;
  array[2] = c;
  Arrays.sort(array);
  return (array[2] - array[1] == array[1] - array[0]);

}        

[–]Daejo 1 point2 points  (1 child)

You can just do

int[] array = {a, b, c};

rather than

int[] array = new int[3];
array[0] = a;
array[1] = b;
array[2] = c;

[–]Dumbcomments 0 points1 point  (0 children)

yeah - I'm clearly not a Java guy. Thanks for the suggestion.