Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    matt_well's Avatar
    matt_well is offline Member
    Join Date
    Jul 2008
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Is there a reason you need to save all the values of x and y?
    What is supposed to be the output from the program?
    You only need to save the last two values of y to compute the new y[i] value.
    Helo Norm, the reason not save the last two values of y, so that the program can get it automatically whenever the file value is another textfile in future I consider.

    First is saved by getting the x[0] from the textfile and assigned it to y[0].
    y[0] = x[0]
    Second, getting the x[1] from the textfile to calculate y[1].
    y[1] = 2*y[0] + x[1]

    Then after that, can calculate the rest.
    y[i] = 2*y[i-1] - y[i-2] + x[i]


    The output should be the output 'y[i]' only.

    Java Code:
            for(int i = 2; i < maxSize; i++)
            {
                String data = getNextValue(fileData, i);
                double value = parseValue(data);
                x[i] = value;
                // What's the way to assign the 'double value' as x[i]?
    
                if(x[0]){
    
    				y[0] = x[0] ; //how to read the first value 'x[0]' only?
    
    			}
    			else if(x[1]){ 
    
    				y[1] = 2*y[0] + x[1]; //how to read the value 'x[1]' only?
    			}
    			else{
    
    				y[i] = 2*y[i-1] - y[i-2] + x[i];
    				}
    
            pw.close();
    		System.out.print( "Output file at C drive now" + '\n');
    		}
    May I know to declare arrayList here in 'double' format?

  2. #22
    matt_well's Avatar
    matt_well is offline Member
    Join Date
    Jul 2008
    Posts
    59
    Rep Power
    0

    Default

    How to read only the x[1]?
    Last edited by matt_well; 07-29-2008 at 09:28 AM.

  3. #23
    matt_well's Avatar
    matt_well is offline Member
    Join Date
    Jul 2008
    Posts
    59
    Rep Power
    0

    Default

    Can guide me?

  4. #24
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by matt_well View Post
    Yes, I know that. How to use it here the double value?
    As of 1.5 and autoboxing, how not to use it with a double value?

    Give it a try.

    ArrayList<Double> ?

  5. #25
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,876
    Rep Power
    25

    Default

    output should be the output 'y[i]' only
    Then you do NOT need to save all of the x and y values, only enough to compute the equation for the current value of i.

    You create an array of doubles by:
    double[] dblArray = new double[<size>];

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 07-01-2008, 10:06 PM
  2. Replies: 9
    Last Post: 06-25-2008, 05:48 AM
  3. Is it possible to make a Phone call program using java?
    By fireball2008 in forum New To Java
    Replies: 2
    Last Post: 05-08-2008, 07:20 PM
  4. Java Question
    By Jay-1.1 in forum New To Java
    Replies: 11
    Last Post: 05-01-2008, 05:04 PM
  5. Make sound play in a java application
    By lenny in forum AWT / Swing
    Replies: 2
    Last Post: 08-13-2007, 12:45 PM

Posting Permissions

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