ICSE Class 10 Computer Applications
Question 18 of 32
Input in Java — Question 18
Back to all questions 18
Question Question 18
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.
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
