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
Arisa [49]
3 years ago
13

I need to create a method named "root positive". which will either print the square root of the number passed to it or if the nu

mber is less than zero, it will print out the statement "Number must not be negative."?
1. Ask the user to input a number of type double which you will find the square root of the number.

2. Create a method called rootPositive which will either print the square root of the number passed to it or if the number is less than zero, it will print out the statement "Number must not be negative.".

3. Call your rootPositive method and pass to it the number the user enetered.
Computers and Technology
1 answer:
rjkz [21]3 years ago
5 0

Answer:

Explanation:

The following code is written in Java. It is a method that calculates the square root of a number as requested. The method first checks with an IF statement if the parameter value is a positive number and then calculates the square root and prints it to the screen. Otherwise, it prints Number must not be negative. A test case has been provided in the main method and the output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.print("Enter a number of type double to calculate square root:");

       double num = in.nextDouble();

       rootPositive(num);

   }

   public static void rootPositive(double num) {

       if (num > 0) {

           System.out.println(Math.sqrt(num));

       } else {

           System.out.println("Number must not be negative.");

       }

   }

}

You might be interested in
Which one of the following downloads and uploads files to and from a server? A. Client B. Internet protocol C. Server D. Worksta
earnstyle [38]
The answer is A. Client request and receive files to and from a server.
5 0
2 years ago
Write a program that prints the Grade based on the given data. 95-100: A+ 90-94: A 80-89: B+ 70-79: B 60-69: C+ 50-59: C <49
mr Goodwill [35]

Answer:

The program to this question as follows:

Program:

score=int(input("Enter your percentage: ")) #input grade by user

#using conditional statement for match condition  

if 95<=score <= 100: #if value in between 95 to 100

   grade = 'A+' #assign grade

elif 90 <=score <= 94: #elif value in between 90 to 94

   grade = 'A' #assign grade

elif 80 <=score <= 89:  #elif value in between 80 to 89

   grade = 'B+' #assign grade

elif 70 <=score <= 79:  #elif value in between 70 to 79

   grade = 'B' #assign grade

elif 60 <=score <= 69:  #elif value in between 60 to 69

   grade = 'C+' #assign grade

elif 50 <=score <= 59:  #elif value in between 50 to 59

   grade = 'C' #assign grade

elif score<49 :  #elif value is less then 49

   grade = 'F' #assign grade

print (grade) #print grade

Output:

Enter your percentage: 50

C

 Explanation:

In the above python code, a variable "score" is defined, this variable is used for taking value from the user end. In the next step if-elif-else conditional statement is used, this statement is used when a group of statements is given in which one is true. The if block check score value is between 95-100 if this is true it will print A+.

In elif block if the above condition is not true, then this condition will execute, in this block, there are multiple elif block is used that can be described as follows:

  • In the first block, if the value in between 90-94. It will print A.
  • In the second block, if the value in between 80-89. It will print B+.
  • In the third block, if value in between 70-79. It will print B.
  • In the fourth block, if value in between 60-69. It will print C+.
  • In the fifth block, if value in between 50-59. It will print C.
  • In the last, if the value of the score is less then 49. It will print F.
8 0
2 years ago
One foot equals 12 inches. Write a function named feet_to_inches that accepts a number of feet as an argument and returns the nu
fenix001 [56]

Answer:

def feet_to_inches( feet ):

      inches = feet * 12

      print(inches, "inches")

feet_to_inches(10)

Explanation:

The code is written in python.  The unit for conversion base on your question is that 1 ft = 12 inches. Therefore,

def feet_to_inches( feet ):

This code we define a function and pass the argument as feet which is the length in ft that is required when we call the function.

inches = feet * 12

Here the length in ft is been converted to inches by multiplying by 12.

print(inches, "inches")

Here we print the value in inches .

feet_to_inches(10)

Here we call the function and pass the argument in feet to be converted  

       

8 0
2 years ago
What landforms are likely to form at this boundary
Paha777 [63]
<span>Landforms that could be created at convergent boundaries would consist of: volcanoes, mountains, trenches, volcanic islands, and even deserts could result from effects of converging boundaries. The landforms are mountains.</span>
3 0
3 years ago
What is a good coding site
Helga [31]

Sratch.com

-Agarvated

6 0
2 years ago
Other questions:
  • Troubleshooting comes before diagnosing. Answer: false
    7·1 answer
  • Assume the following variable definitions int a = 5, b = 12; double x = 3.4, z = 9.1. What are the values of the following expre
    7·1 answer
  • Which of the following terms describes surgery through a small incision in the abdomen?
    11·1 answer
  • What should you remember when using the thesaurus to replace words?
    8·2 answers
  • How do I learn coding? Python
    5·2 answers
  • What is Quantum Cryptography? How is it different from Public and Private-key transactions?
    6·1 answer
  • ______ is the ability of a system to do more than one thing at a time. A. Multibusing c. online processing b. Multiprocessing d.
    13·1 answer
  • Search..
    14·1 answer
  • a bus is full of passengers. if you count them by either twos, threes, or fives, there is one left. if you count them by seven t
    10·1 answer
  • The field of ____ is concerned with the technical issues involved in information display. computer science
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!