1

I am trying to take a two-dimensional array and run it through a series of calculations in order to transform it into a one-dimensional array. However, when I run my program I keep getting this long error

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    Duplicate local variable raw_advisor
    Syntax error on token "i", delete this token
    Type mismatch: cannot convert from double to double[]
    Syntax error on token "i", delete this token
    Type mismatch: cannot convert from double to double[]
    Duplicate local variable advisor_score
    Syntax error on token "i", delete this token
    Type mismatch: cannot convert from double to double[]

    at Advisor_Score.main(Advisor_Score.java:16)

Here is what my code looks like:

import java.lang.Math;
public class Advisor_Score {
    public static void main(String[] args){ 
        double l[] = {1};
        double k[] = {2,2};
        double m[] = {3,3,3};
        double All_users[][]={l,k,m};
        double sum[]={0,0,0};
        double [] raw_advisor=new double [3];
        double [] advisor_scored_scaled= new double [3];
        double []advisor_score= new double [3];
        for (int i=0;i<All_users.length;i++){
                for(int j=0;j<All_users[i].length;j++){
                        sum[i]+=All_users[i][j];
                }
                double raw_advisor[i]=(sum[i]-(3*All_users[i].length))/4;
                double advisor_score_scaled[i]= 2.5*(1-Math.pow(Math.E, -.5*raw_advisor[i]));
                double advisor_score[i] = (2.5 + advisor_score_scaled[i]);
                System.out.println(advisor_score[i]);
                }       
    }
}

Thanks in advance! Sorry I am new to programming.

1 Answer 1

4

You can't specify the type when assigning to the values inside the for loop. In Java, variables are defined once with a specific type. That type can't be changed later on in the program, so it does not need to be specified. You also had a typo when defining advisor_score_scaled. Try this:

import java.lang.Math;
public class Advisor_Score {
    public static void main(String[] args){ 
        double l[] = {1};
        double k[] = {2,2};
        double m[] = {3,3,3};
        double All_users[][]={l,k,m};
        double sum[]={0,0,0};
        double [] raw_advisor=new double [3];
        double [] advisor_score_scaled= new double [3];
        double []advisor_score= new double [3];
        for (int i=0;i<All_users.length;i++){
                for(int j=0;j<All_users[i].length;j++){
                        sum[i]+=All_users[i][j];
                }
                raw_advisor[i]=(sum[i]-(3*All_users[i].length))/4;
                advisor_score_scaled[i]= 2.5*(1-Math.pow(Math.E, -.5*raw_advisor[i]));
                advisor_score[i] = (2.5 + advisor_score_scaled[i]);
                System.out.println(advisor_score[i]);
                }       
    }
}

It compiles and runs for me. Not sure of course if it gives the answer you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.