Reputation: 1
How can I trap a particular value of the counter in the for loop, for which I get the maximum calculated value ..for example:
import com.imonPhysics.projectile2;
public class motion2{
public static void main(String[] args){
double range=0,v=35,maxrange=0,angle=0;
int x=0;
projectile2 p1=new projectile2();
System.out.println("the given velocity is: 20 m/s \n" );
System.out.println("The value of g is: 9.8 m/s^2\n\n" );
for(int j=0;j<=90;j+=5){
x=j;
range=p1.calculate(v,j);
System.out.println("For the angle :" + j+" the range is: " + range);
if(range > maxrange)maxrange=range;
}
System.out.println(" the maximum range is :"+ maxrange);
System.out.println(" the angle at which the range is max is : " + angle);
}
}
how can I trap the angle for maxrange.
Upvotes: 0
Views: 58
Reputation: 2843
Maybe I don't understand the problem correctly, but do you if you want the angle with that the max range is reached, then just do angle = j
inside the if.
Upvotes: 1
Reputation: 129507
If I understand your question correctly, you can use exactly the same approach you are using to determine maxrange
:
for (...) {
...
if (range > maxrange) {
maxrange = range;
angle = j; // <--
}
}
Upvotes: 5