Declan McKenna
Declan McKenna

Reputation: 4870

Setting an int so it is always the greater value?

I have a simple function as defined below:

if(currentValue < smallestValue)
 {
    smallestValue = currentValue;
 }

What can I initialize smallestValue to so it will always be greater than the first currentValue?

Upvotes: 0

Views: 57

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

By this rule: CurrentValue can be any real number, use Double.MAX_VALUE:

double smallestValue = Double.MAX_VALUE;

But the second rule negates the previous: All my values are ints, so use Integer.MAX_VALUE

int smallestValue = Integer.MAX_VALUE;

Upvotes: 1

Related Questions