I am new to java, and we are learning arrays in class. I have a problem from my CS textbook that I have been working on. I know generally what I am supposed to do, but I do not know if the syntax for what I would like to add to the code fragment would be syntactically proper. The textbook sounds like it wants me to add code on the next line; instead, I would have modified the second declaration and assigned the length to it on the same line. I have found a few other similar questions on here, but since I am new to this, I dont really understand those answers, and would like to know specifically why this one is the way it is :)
This is the book question:
What needs to be added to the following code fragment so that all values except the first two (100000.0 and 110000.0) are copied from allSalaries to workerSalaries?
Here is the code fragment I am given:
double[] allSalaries = {100000.0, 110000.0, 25000.0, 18000.0, 30000.0, 9000.0, 12000.0};
double[] workerSalaries;
Would it still be syntactically proper if I did on the next line:
workerSalaries = new double[allSalaries.length - 2];
Or would I replace the second line of the fragment with this:
double[] workerSalaries = new double[allSalaries.length - 2];
Thanks!!