Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program, Sqrt, to compute the square root of a given integer. It should have a main method that calls a static method
Write a program, Sqrt, to compute the square root of a given integer. It should have a main method that calls a static method called square root that computes the square root of the number passed to it as a parameter and returns its square root. The number whose square root needs to be computed would be passed to the program as a command-line argument. If it is a negative number, it should say "Cannot compute the square root of a negative number". Otherwise it should compute (by calling the square root method) and print out the square root of the given number. You can use the sqrt(int) in- built method of Java. Sample runs would be as follows: > java Sqrt 0 The square root of the given number is 0.0 > java Sqrt -6 Cannot compute the square root of a negative number > java Sqrt 9 The square root of the given number is 3.0 > java Sqrt 6 The square root of the given number is 2.449489742783178 Note that you would need to implement it using a static method for full credit.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started