Computer Applications
Write a program to compute the Time Period (T) of a Simple Pendulum as per the following formula:
T = 2π√(L/g)
Input the value of L (Length of Pendulum) and g (gravity) using the Scanner class.
Java
Input in Java
30 Likes
Answer
import java.util.Scanner;
public class KboatSimplePendulum
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Length: ");
double l = in.nextDouble();
System.out.print("Enter Gravity: ");
double g = in.nextDouble();
double t = 2 * 3.14159 * Math.sqrt(l / g);
System.out.println("Time Period = " + t);
in.close();
}
}
Output
Answered By
15 Likes
Related Questions
Write a program in Java that takes input using the Scanner class to calculate the Simple Interest and the Compound Interest with the given values:
i. Principle Amount = Rs.1,00,000
ii. Rate = 11.5%
iii. Time = 5 years
Display the following output:
i. Simple interest
ii. Compound interest
iii. Absolute value of the difference between the simple and compound interest.
Write a program that takes the distance of the commute in kilometres, the car fuel consumption rate in kilometre per gallon, and the price of a gallon of petrol as input. The program should then display the cost of the commute.
Write a statement to let the user enter an integer or a double value from the keyboard.
Write a program in Java that accepts the seconds as input and converts them into the corresponding number of hours, minutes and seconds. A sample output is shown below:
Enter Total Seconds: 5000 1 Hour(s) 23 Minute(s) 20 Second(s)