
When an object is falling because of gravity, the following formula can be used to determine the distance of the object falls in a specific time period.
d = 1/2 gt2
The Variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the object has been falling.
Write a method named fallingDistance that accepts an object's falling time (in seconds) as an argument. The method should return the distance, in meters, that the object has fallen during that time interval. Demonstrate the method by calling it in a loop that passes the value 1 through 10 as arguments, and displays the return value.
Hint: import the class DecimalFormat from library text to have the output in the following format "0.00".

import java.util.*;
import java.text.*;
public class FallingDistance{
public static double fallingDistance(double fallingTime){
double a=0.5, g=9.8;
double d=(a*g)*(fallingTime*fallingTime);
return d;
}
public static void main(String [] args){
DecimalFormat df=new DecimalFormat("##.##");
double fallingTime;
Scanner input=new Scanner(System.in);
System.out.print("Ener the falling time (in seconds): ");
fallingTime=input.nextDouble();
for(int x=1;x<11;x++){
System.out.println(df.format(fallingDistance(x)));
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.