- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
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:
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:
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);
