Write a program in Java to calculate and display the final velocity by taking the initial velocity,acceleration and the distance covered as inputs.
Answers
Formula used and Explanation :
v² - u² = 2as
Where,
v = final velocity
u = initial velocity
a = acceleration
s = distance
As we need to find the final velocity, where initial velocity, acceleration and distances are inputted, the formula will be moulded as :
v² = 2as + u²
v = √(2as + u²)
And we import Math library to access the sqrt() function that helps in computing the square root operation.
Language used : Java Programming.
Note :
I have attached the program and it's compilation, with the output as an attachment. Have a look at it. I have compiled the code on java editor, and the code is perfect!
Program :
import java.util.Scanner;
import java.lang.Math;
public class CalculatingFinalVelocity
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the initial velocity :");
int u = sc.nextInt();
System.out.println("Enter the acceleration :");
int a = sc.nextInt();
System.out.println("Enter the distance :");
int s = sc.nextInt();
int finalvelocity = (2*a*s)+(u*u);
System.out.println("Final velocity is : "+Math.sqrt(finalvelocity)+" units.");
}
}
Input :
Enter the initial velocity : 15
Enter the acceleration : 6
Enter the distance : 40
Output :
Final velocity is : 26.551836094703507 units.
Hope it helps. If yes, leave a smile. :)
Answer:
import java.util.Scanner;
import java.lang.Math;
public class CalculatingFinalVelocity
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter the initial velocity :");
int u = sc.nextInt();
System.out.println("Enter the acceleration :");
int a = sc.nextInt();
System.out.println("Enter the distance :");
int s = sc.nextInt();
int finalvelocity = (2*a*s)+(u*u);
System.out.println("Final velocity is : "+Math.sqrt(finalvelocity)+" units.");
}
}
Explanation: