write a program in scanner class of java for the question.
Attachments:
Answers
Answered by
6
/* Description is given as comments.
* Copy it into an IDE so code and comments are visible properly.
* Some screenshots are attached.
*/
import java.util.Scanner;
public class TimePeriod
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter length: "); //Asking for User Input for Length
double l = sc.nextDouble(); //Scanning User Input
System.out.print("Enter gravitational acceleration: "); //Asking for User Input for g
double g = sc.nextDouble(); //Scanning User Input
double pi = 22; //Creating a value of pi
pi = pi/7;
double T = 2*pi*Math.sqrt(l/g); //Calculating Time Period
System.out.println("\nThe Time Period is: "+T+" seconds");
}
}
* Copy it into an IDE so code and comments are visible properly.
* Some screenshots are attached.
*/
import java.util.Scanner;
public class TimePeriod
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter length: "); //Asking for User Input for Length
double l = sc.nextDouble(); //Scanning User Input
System.out.print("Enter gravitational acceleration: "); //Asking for User Input for g
double g = sc.nextDouble(); //Scanning User Input
double pi = 22; //Creating a value of pi
pi = pi/7;
double T = 2*pi*Math.sqrt(l/g); //Calculating Time Period
System.out.println("\nThe Time Period is: "+T+" seconds");
}
}
Attachments:
Similar questions