Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Input in Java

Chapter 6

Input in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Time Period of a Simple Pendulum


Write a program to compute the Time Period (T) of a Simple Pendulum as per the following formula:

Java Programs

Input the value of L (Length of Pendulum) and g (gravity) using the Scanner class.

 

import java.util.Scanner;

 

public class SimplePendulum {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        // Input values

        System.out.print("Enter the length of the pendulum (L): ");

        double L = sc.nextDouble();

 

        System.out.print("Enter the value of gravity (g): ");

        double g = sc.nextDouble();

 

        // Calculation

        double T = 2 * Math.PI * Math.sqrt(L / g);

 

        // Output

        System.out.println("\nTime Period of the Pendulum = " + T + " seconds");

 

        sc.close();

    }

}

Output

 
SAMPLE INPUT : 
Enter the length of the pendulum (L): 1
Enter the value of gravity (g): 9.8

SAMPLE OUTPUT : 
Time Period of the Pendulum = 2.0060666807106475 seconds

Explanation

The time period of a simple pendulum is calculated using the formula:

Java Programs

Where:

  • L = Length of the pendulum
  • g = Acceleration due to gravity
  • π (Pi) = 3.14159 (provided by Math.PI)

Java Methods Used:

  • Math.PI → provides the value of π
  • Math.sqrt() → calculates square root

Key Concepts Used

  • Scanner class for user input
  • Mathematical expressions
  • Math.PI and Math.sqrt()

Formatted Output

System.out.printf("Time Period of the Pendulum = %.2f seconds", T);