Q- Write a program to accept values through the main method. The values to be accepted are distance travelled and time taken. The program should be print speed of moving objects.
Answers
Explanation:
When an object moves in a straight line at a steady speed, we can calculate its speed if we know how far it travels and how long it takes. This equation shows the relationship between speed, distance traveled and time taken:
Speed is distance divided by the time taken.
For example, a car travels 30 kilometers in 2 hours.
Its speed is 30 ÷ 2 = 15km/hr.
Formula used :
Distance = Speed * Time Time = Distance / Speed Speed = Distance / Time
hope it helps u
//program to accept things in main method
public class speed
{
public static void main ( double d, double t)
{
double s = d/ t;
System.out.println("The speed of the moving object is"+s);
}
}
Explanation: double is used for decimals having more than one number after decimal point. As distance can be in decimals and time can also be written in decimals double is used we can use int also in place of double