java - Illegal Start of Expression Error in Array -
i trying write method prompts user size of array, , value of each index value, tested in driver.
i keep getting "] expected" error, , "illegal start of expression" error @ double arr[i]
section , wondering why?
public void setarray(double[] arr) { int size = sc.nextint(); double[] array = new double[size]; for(int = 0; < size; i++) { system.out.println("enter value : "); double arr[i] = sc.nextdouble(); //error here } }
this compiler returns:
golightlyscottarray.java:26: error: variable arr defined in method setarray(double[]) double[] arr = new double[size]; ^ golightlyscottarray.java:26: error: incompatible types: possible lossy conversion double int double[] arr = new double[size]; ^ 2 errors
you've defined variable "arr" in method declaration can't use define again, doing putting word double @ start of line. remove word double , update existing variable instead of attempting create new one.
Comments
Post a Comment