# Thread: Storing coefficients into an array

1. Member
Join Date
Feb 2011
Posts
3
Rep Power
0

## Storing coefficients into an array

Basically I'm not sure how to correctly store this array. I have a lot of an assigned program completed but the only issue is I cant seem to figure out what the best approach (or any) to completing this portion. I would really appreciate any help given.

int[] coeff_exp;// declare coeff_exp as an array of int
coef_exp = // here you should store the coefficients and the exponents of the Polynomial as explained in the specification
// In the coeff_exp array you can store only the coefficients.
// The exponents can be considered as the array indexes.
// For example, the polynomial: 2x^5 - 3x^2 + 4 is represented in the following way by the coeff_exp array
// array content: 2 0 0 -3 0 4
// array index: (5) (4) (3) (2) (1) (0)

2. I'm not positive what the issue is, just what the array would look like? Or how you would parse the polynomial to store it to the array?

For the example:
Java Code:
```coeff_exp[5] = 2; // 2x^5
coeff_exp[4] = 0;
coeff_exp[3] = 0;
coeff_exp[2] = -3; // - 3x^2
coeff_exp[1] = 0;
coeff_exp[0] = 4; // + 4```

3. Member
Join Date
Feb 2011
Posts
3
Rep Power
0
I actually have a string representation of the polynomial which I suppose I'm trying to parse into the array.

relatively new to parsing information. I have text file which contains the following

2 5 -3 2 4 0
equating to

2^5 + -3^2 + 2^2 + 4

basiclly I need to take this data and load it into the array as follows

// array content: 2 0 0 -3 0 4
// array index: (5) (4) (3) (2) (1) (0)

4. Take a look at the Scanner class to load data from a text file. Once you get the line from the file into a string you can just use the split method to cut out the numbers. Then you'll have an array of (coefficient, exponent, coefficient, exponent....) and you can use a loop to assign them to another array in the wanted way. (arr[exponent] = coefficient).

5. Member
Join Date
Feb 2011
Posts
3
Rep Power
0
Still unsure of the issue here. would anyone be willing to have a skype chat with me to help me run through my code. I would really appreciate it

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•