I have a program, that is supposed to calculate the sum of the numbers, retrieve the smallest of the set, and how many numbers were entered.

But, the sum+= function I have is not properly calculating when negative numbers are entered

For instance with a data set of -1, -2, and 8. The sum printed should be 5, and my program prints -3.Code:`{`

public static void main(String [] args)

{

int numberOfInt;

int numberIn;

int small;

int sum = 0;

Scanner input = new Scanner(System.in);

System.out.print("Please, enter the numbers you would like in the set: ");

numberOfInt = input.nextInt();

if(numberOfInt > 0)

{

System.out.print("Please enter your first number: ");

numberIn = input.nextInt();

small = numberIn;

for(int j = 2 ; j <= numberOfInt ; j++)

{

sum += numberIn;

System.out.print("Please enter your next number: ");

numberIn = input.nextInt();

if(numberIn < small)

small = numberIn;

}

System.out.println("The sum of set is: " + sum);

System.out.println("The smallest number in the set is: " + small);

System.out.println("The number of numbers entered was: " + numberOfInt);

}

else

System.out.println("The set empty, therefore no sum, smallest number or count exist.");

}

}

What function should I use instead of sum+ to fix this tiny problem?