I would like to print one message during my loop only after crossing the speed of sound.
I've found on the following topic someone explaining how to do it with a boolean but I didn't get it.
This is what I've tried :
boolean oneTime = (vitesse > 343)
if (oneTime)
System.out.println("Felix depasse la vitesse du son");
And my code
while (h > 0)
{
while (speed < 343 && accel>0.5)
{
double s = surface/ masse;
double q = Math.exp(-s*(t-t0));
vitesse = (g/s)*(1-q) + v0*q;
hauteur = h0 - (g/s)*(t-t0)-((v0-(g/s))/s)*(1-q);
accel = g-s*vitesse; //formula to compute the fall of a body
if (h > 0 )
{
if (speed > 343)
{
System.out.println("## Felix depasse la vitesse du son");
System.out.printf("%.0f, %.4f, %.4f, %.5f\n",t, hauteur, vitesse, accel);
}
else if (accel <0.5)
{
System.out.println("## Felix depasse la vitesse du son");
System.out.printf("%.0f, %.4f, %.4f, %.5f\n",t, hauteur, vitesse, accel);
}
else
System.out.printf("%.0f, %.4f, %.4f, %.5f\n",t, hauteur, vitesse, accel);
}
++t;
}
}
execute an instruction only one time in a do while loop in java