Results 1 to 5 of 5
  1. #1
    shanus180 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default 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. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default

    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. #3
    shanus180 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    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. #4
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default

    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. #5
    shanus180 is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default

    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

Similar Threads

  1. Need help with array and storing input
    By Bewitched1 in forum New To Java
    Replies: 8
    Last Post: 07-24-2010, 06:16 PM
  2. Storing a record set into an array
    By DJCali in forum New To Java
    Replies: 2
    Last Post: 10-25-2009, 03:47 PM
  3. Storing in an Array
    By Bascotie in forum New To Java
    Replies: 10
    Last Post: 10-15-2009, 06:12 AM
  4. storing a string in an array
    By tiyani in forum New To Java
    Replies: 3
    Last Post: 08-12-2009, 08:25 PM
  5. storing strings into an array
    By anthonym2121 in forum New To Java
    Replies: 2
    Last Post: 04-04-2009, 08:32 AM

Tags for this Thread

Posting Permissions

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