if (num > 0) {
sum += num;
}


For efficiency, the test should be greater than, because if num is 0, adding 0 to sum leaves sum unchanged.