I cannot seem to be able to get this code to properly average numbers. When i input 5 numbers that are 1 digit such as 9, 6, 2 etc. it gives me incorrect results, such as putting in five 2's, it will give me the answer '0.0'. Even when inputting numbers with two or more digits it rounds the number incorrectly. Its like its not even recognising it as being a double. I think i am missing something extremely obvious, haven't programmed in a while so wouldn't be surprised.
Here is the code:
import java.util.*;
public class LittleBoxes2
{
public static void main (String[] args)
{
Scanner input = new Scanner (System.in);
int[] num;
double avg;
String cont = "Y";
while(cont.equals("Y") || cont.equals("y"))
{
num = new int [5];
for(int i = 1; i <= 5; i++)
{
System.out.println("Enter number " + i + ".");
num[i - 1] = input.nextInt();
}
avg = num[0] / 5 + num[1] / 5 + num[2] / 5 + num[3] / 5 + num[4] / 5;
System.out.println("The average number is: " + avg + ".");
System.out.println("Do you want to continue? (Y/N)");
input.nextLine();
cont = input.nextLine();
}
}
}