1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
attashe74 [19]
4 years ago
15

Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value

. Prompt the user for an input value and try the Math.sqrt() method on it. The application either displays the square root or catches the thrown Exception and displays the message Can't take square root of negative number
Computers and Technology
1 answer:
lozanna [386]4 years ago
3 0

The code for the program described in question:

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {

       double number;

       double squareRootOfNumber;

       String userInput = null;

       Scanner scanner = new Scanner(System.in);

       System.out.println("Enter the number: ");

       userInput = scanner.next();

       number = Double.parseDouble(userInput);

       squareRootOfNumber = Math.sqrt(number);

       if (number < 0) {

           throw new ArithmeticException("Can't take square root of negative number");

       }

       System.out.format("Square root of number entered is %.2f %n", squareRootOfNumber);

   }

}

The output of the program will be:

Enter the number:

-90

Exception in thread "main" java.lang.ArithmeticException: Can't take square root of negative number at com.brainly.ans.Test.main(Test.java:18)

Explanation:

Function from standard Java library <em>java.lang.Math.sqrt</em> will <em>not throw</em> an <em>ArithmeticException</em> even its argument is negative so there is no reason to surround your code try/catch block.

Instead, we have thrown ArithmeticException manually by using <em>throw</em> keyword:

<em>throw new ArithmeticException("Can't take square root of negative number");</em>

You might be interested in
Convert ⅖ pie radian to degree​
aniked [119]

Answer:

Convert to a decimal.

22.9183118°

Explanation:

7 0
3 years ago
You have observed that Alexander Rocco Corporation uses Alika’s Cleaning Company for its janitorial services. The company’s
Rzqust [24]

Answer:

Explanation:

Relevance of Thrown Items:

  •    The thrown items mainly consist of the Windows NT training kit, outdated magazines and some written notes, etc. All these things can be used in the company for training the fresh talent.
  •    These things must be used for the purpose of training fresh people and the things like programs written in HTML must not be dumped like this because they consists of the raw code which can be harmful if gotten into wrong hands.
  •    Hence, the information like this must be taken care of seriously as these can be loopholes into companies down.
  •    Rest of the things like food wrappers, empty bottles, resume copies are all worthless to the company and can be thrown into the dump as soon as possible.The business cards must also be thrown if not important.

Recommendation To Management:

  •    The management must take these things seriously and must double check the company properties before throwing them into dump. There must be a committe build to check the things that are been going directly to the dump.
  •    They must have the responsibility for checking the things before going to the dump and must filter all the important things from the garbage back to the shelves of the office.
  • Hence, these things must be taken care of so that no harm is to be done to the company.

cheers i hope this helped !!

5 0
4 years ago
Pls Help A table is a_______of rows and columns that provides a structure for presenting data​
WARRIOR [948]

Answer:

Graph or chart???

Explanation:

5 0
3 years ago
Which of the following is an advantage to using internal databases for​ information? A. Internal information is accurate and com
Irina-Kira [14]

Answer:

C. They can be accessed quickly and cheaply.

Explanation:

An internal database is information that can be obtained inside the company through internal networks. This information can be easy to get as it is in the network of the company and you have access to it and it also have a low cost as you don't have pay money to get it. According to this, the answer is that an advantage to using internal databases for​ information is that they can be accessed quickly and cheaply.

The other options are not right because internal information can be  outdated and incomplete if it is not updated by people in the company and it can be found in different forms and it is not always easy to manage as this depends on the applications used and how the company decides to visualize it.

3 0
3 years ago
What are the arguments both for and against the exclusive use of boolean expressions in the control statements in java (as oppos
sineoko [7]

Reliability is the major argument for the exclusive use of Boolean expressions (expressions that result to either true or false) inside control statements (i.e. if…else, for loop). Results from control statements become reliable because Java has disallowed other types to be used. Other types, like arithmetic expressions in C++ oftentimes include typing errors that are not detected by the compiler as errors, therefore causing confusion.

7 0
3 years ago
Other questions:
  • Which payment type is best if you are trying to sick to a budget?
    15·1 answer
  • Write a function get_initials(the name) that takes a string of a name and returns the initials of the name, in upper case, separ
    12·1 answer
  • How is marketing related to the other functions of a business
    14·1 answer
  • An engineer's desktop PC connects to a switch at the main site. A router at the main site connects to each branch office through
    5·1 answer
  • Write an algorithm which gets a number A, if it is even, prints even, and if it is odd prints odd.
    7·1 answer
  • Small data files that are deposited on a user's hard disk when they visit a website are called _______.
    6·2 answers
  • Where does an antivirus run suspicious applications?
    12·1 answer
  • I am writing a Python code to ask a user to enter students' information including name,
    10·1 answer
  • Which generation computer supported GUI operating system?​
    11·1 answer
  • How to fix this? Zoom it in to see it better
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!