Skip to Main Content

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

SurajRFeb 5 2022 — edited Feb 5 2022

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);  
}  

}

Comments
Post Details
Added on Feb 5 2022
0 comments
158 views