KnowledgeBoat Logo

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

28 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

BlueJ output of 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.

Answered By

13 Likes


Related Questions