Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: A Dual loop and methods

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Default A Dual loop and methods

    Hi all,
    Im getting to grips with some java but having trouble with this loop. I'll explain it just so we're on the same page

    im trying to create a loop whereby the time and velocity change each time. I have all the classes and methods necessary and compile up to this loop.

    By this i mean, i have the user to ask how many data points they wish to consider (excluding zero as a data point)
    i do this by
    double m = input.nextDouble(); 
    double step = t/m;

    In normal words time is divided by the number of data points hence this is ideal in the loop to us j+=step rather than say 1, 2, 3, 4... which restricts user ability and freedom.

    Now, because of the physics (don't worry - simple stuff), the velocity is going to change at each time step. I.e. initial values the user enters e.g. at t = 0, v = (1,0,0)

    Again don't worry about the vector, i have solved that part in terms of print, display and so forth.

    But how should i do this loop? Here was an attempt which failed:

    for(double j = 0; j < v; j+=step)/**needs two loops i.e. begins with t=0, u=v (in this case), then t = step, u = old vf, then t = 2step, u = (new)old vf ...*/
    				fetch.calcVelocityf(v, g, t);
    				v = fetch.getVelocityf(v, g, t);
    				System.out.print(v.returnString() + "\t");
    				for (double i = 0; i < t; i+=step) 

    In reality terms i want it to give me the velocity and time at each step (data point, user entry see above) and have it sent to print.
    I believe the time approach is fine, but unsure on the velocity, v as it is a vector hence j < v means nothing as one is double and the other Vector clas assigned.

    Ps don't worry about g, that is the acceleration - also needed!

    fetch is from:
    Vector fetch = Vector(); [This is the class i use to make them as vectors, print as vectors via returnString etc]
    velocityf is simly final velocity which in this case is changing up until we get the correct number of data points.

    If you feel like i could be more informative let me know

  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    My Mood
    Thanked 104 Times in 90 Posts

    Default Re: A Dual loop and methods

    Welcome rarman,

    Excellent first post, thank you for actually making it so!

    Now if I understand your question correctly you are trying to figure out what your conditional statement for your first for loop is, you are going to require a finishing point, which unless I missed you don't seem to have defined, thise could be a t value or a velocity value.


Similar Threads

  1. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 07:57 PM
  2. For loop; Problems with my for loop
    By mingleth in forum Loops & Control Statements
    Replies: 5
    Last Post: November 16th, 2011, 06:24 PM
  3. [SOLVED] My while loop has run into an infinite loop...?
    By kari4848 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 1st, 2011, 11:05 AM
  4. Odd and Even Numbers Logics in FOR and IF Loop methods
    By mparthiban in forum Loops & Control Statements
    Replies: 2
    Last Post: May 12th, 2010, 05:19 AM
  5. hi. i want to rewrite this do loop into a while loop.
    By etidd in forum Loops & Control Statements
    Replies: 3
    Last Post: January 26th, 2010, 04:27 PM