0

I have a file scanner that reads from a file, a bunch of numbers (doubles) and stores them in tmpVal[]. I would then like to pass it to another method (make_abs_val) to get the absolute value of those numbers, so I can print it to a textview and/or write it to a file. What I'm not sure about is using the new array after I abs value it... I'm getting ".class expected" . . .

//get from file into first array
//this is all part of the mainActivity
while(fileScn.hasNext()){
            val = fileScn.nextDouble();
            tmpVal[arrayNum] = val;
            arrayNum++;

        }

// this is where I'm getting the error, not sure what to do.
make_it_abs(tmpVal[]);

//output to textview
for (int a = 0; a < arrayNum; a++ ){
            txtVw.setText(String.format("%.2f", /*Not sure what variable to use */) + "\n");
        }

//required method to get abs val
                             
public double[] make_it_abs(double orig[]){
        for(int i=0; i < orig.length; i++){
            orig[i] = Math.abs(orig[i]);
        }
        return orig;
    }

2 Answers 2

1

Your method is preceeded by a raw for-loop (and you appear to want to index the array tmpVal, and you can use %n in a format for a new-line). Also, you pass a method an array with the name (no [] needed). Something like,

    make_it_abs(tmpVal);
    for (int a = 0; a < arrayNum; a++){
        txtVw.setText(String.format("%.2f%n", tmpVal[a]));
    }
} // <-- this is missing

//required method to get abs val                         
public double[] make_it_abs(double orig[]){
    for(int i=0; i < orig.length; i++){
        orig[i] = Math.abs(orig[i]);
    }
    return orig;
}
Sign up to request clarification or add additional context in comments.

1 Comment

That extra curly braces is there actually. I did just solve it myself, thanks though!
0

Replace make_it_abs(tmpVal[]) with make_it_abs(tmpVal).

2 Comments

Getting a "make_it_abs cannot be applied"
Are you sure tmpVal's type is double[]?

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.