Forum Stats

  • 3,815,945 Users
  • 2,259,117 Discussions
  • 7,893,340 Comments

Discussions

Syntax error on token "=", Name expected after this token (in bold text)

SurajR
SurajR Member Posts: 1 Green Ribbon
edited Feb 5, 2022 4:27PM in Java in Education

public class TestArray {

    public static void main(String[] args) {

       

        int a[] = new int[5];       //Declaration and initialiation

        a = {10, 20, 30, 40, 50};   //Initialization

        //Traversing array

        for (int i = 0; i < a.length; i++) { //length is the property of array

            System.out.println(a[i]);

        }

        //Average calculation

        float sum = 0, avg;

        for (int i = 0; i < a.length; i++) //Calculating the sum of the numbers

            sum += a[i];

        avg = sum/a.length;

        System.out.println("Average = " + avg);

    }

}