Illegal Array Initialisation? (Java) -


public class {     float[] arr=new float[]{0.1f,0.2f};      arr[0]=0.2f;      public static void main(string []args) {         my= new my();         system.out.println(my.arr[0]);     } } 

i got errors:

my.java: 4 : error: ']' expected  arr[0]=0.2f;  ^ my.java: 4 : error: ';' expected  arr[0]=0.2f;  ^  my.java: 4 : error: illegal start of type  arr[0]=0.2f;  ^ my.java: 4 : error: <identifier> expected  arr[0]=0.2f;  ^ 

is there way use arr[0]=somevalue; ? in c?

you can either fix initializer of arr hold right value start

float[] arr=new float[]{0.2f,0.2f}; 

or can change class change value inside constructor:

public class {     float[] arr=new float[]{0.1f,0.2f};      public my() {         arr[0]=0.2f;     }      ... } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -