JavaCalculate Time From Speed And Distance?
I want an algorithm to compute time out of given velocity and length.Basically I’m using the services of Java but I do believe it might be the similar in additional programming languages too.For case:
velocity = 75 mph
range = 24 miles
A better solution is 19 minutes along with 12 mere seconds.I use 24 * SIXTY / 75 to receive the moments, but MY SPOUSE AND I can’t obtain seconds.
Thank you in improve.
Algorithm
ONE PARTICULAR.Declare changing speed as double
A COUPLE OF.Declare changing distance as double
SEVERAL.Declare changing time as double
4.Input the velocity and store within a variable speed
5.Input the length and store within a variable distance
6TH.Calculate the time by dividing way away by acceleration i.e time = distance/speed
SEVERAL.Output this time
Espresso code
scan java.io.*;
school Time
criminal court static void main(String args)
dual speed, range, time;
Scanner in = different Scanner(System.in);
System.out.println(“Please type in the speed”);
velocity = around.nextDouble();
System.out.println(“Please type in the distance”);
range = around.nextDouble();
occasion = distance/speed;
System.out.println(“Time is actually hours will be “+time+”\n Period in mins is ” + time*60+”\nTime inside seconds will be “+time*60*60);
In order to get the actual seconds just multiply internet with 3600.Since one hour contains SIXTY minutes as well as a minute may contain 60 seconds.That’s why 60*60 = 3600.
So time inside seconds = 3600*distance(in miles)/speed(in mph)
Within your above case time with seconds = 3600*24/75 = 1152 mere seconds = 19 minutes TWELVE MONTH PERIOD seconds
Many thanks, hope that helps
If you want to play all around with integers along with modulus:
int velocity = 75
int dist = 24
int hours = dist/speed
int dminutes = ((dist PER-CENT speed) * 60)
int units = dminutes / speed
int moments = ((dminutes PER CENT speed) * 60) / pace.
Leave a Reply
You must be logged in to post a comment.