Q:

Using a for loop to read ONLY 5 numbers and average them. JAVA

Really having issues with this program I'm making. I've searched this site and a few others, although have yet to find a solution. It may look like I'm just soliciting help but I truly am stuck. I am to make a program that reads in 5 numbers from the user and average those numbers. My extent of knowledge of Java is the Scanner class and for loops, yet haven't used while loops yet. Here is the very poorly written code:
public class Average5
{
   public static void main(String args[])
{
   Scanner sc = new Scanner(System.in);
   int num;

   System.out.print("Please enter a number: ");
   num = sc.nextInt();

   for(int num1 = 0; num1 <= num; num1++)
   {
        System.out.print("Please enter a number: ");
        num = sc.nextInt();
   }

I honestly have no clue what to do. More or less self taught.

A:

public class Average5 {

    public static void main(String args[]) {

        int numlenngth = 5;
        double total = 0;
        Scanner sc = new Scanner(System.in);

        for (int num1 = 0; num1 < numlenngth; num1++) {
            System.out.print("Please enter a number: ");
            total += sc.nextInt();
        }

        System.out.println("Average : " + (total / numlenngth));

    }
}

output >>
Please enter a number: 1
Please enter a number: 1
Please enter a number: 1
Please enter a number: 1
Please enter a number: 2
Average : 1.2

