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.

>> REGISTER NOW TO START POSTING

# Thread: A Dual loop and methods

1. ## 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)
{
System.out.print(t);
}

}
}

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!

Note:
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. ## 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.

Chris