Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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
757 views