Question

21 If x is greater than or equal zero, then assign the square root of x to variable sqrtx and print out the result Otherwise,write Java statements that perform the following functions ?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.lang.Math;
class Greater
{
public static void sqrt(int x)
{
double sqrtx;
if(x>=0)
{
sqrtx= Math.sqrt(x);
System.out.println(sqrtx);
}
else
{
System.out.println("The argument passed to find the square root cannot be negative");
sqrtx=0;
}
  
}
public static void main(String []args)
{
sqrt(9);
}
}

*****************************************************************************
Chegg allows me to answer specific no of questions including the sub parts , so please do post the rest of the questions as a separate query as per Chegg Guidelines. Thank you :)
*****************************************************************************
PLEASE DO UPVOTE IF THE ANSWER IS HELPFUL
*****************************************************************************

Add a comment
Know the answer?
Add Answer to:
write Java statements that perform the following functions ? 21 If x is greater than or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Use Python Write a script to perform various basic math and string operations. Use some functions...

    Use Python Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals the remainder of 5 divided by 3 Built-in functions abs, round, and...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • C Language <stdio.h> (FUNCTIONS) A concrete company wants to estimate what it will cost a customer...

    C Language <stdio.h> (FUNCTIONS) A concrete company wants to estimate what it will cost a customer to have a driveway poured. They can pour a 3 inch deep 200 sq. ft. driveway in 3 hours, and they charge $50.00 per hour as their labor rate. Write a program to ask the user for the length of the driveway (in feet), and the width of the driveway (in feet) to be poured. For both the length and width, make sure the...

  • Write the following functions, as defined by the given IPO comments. Remember to include the IPO...

    Write the following functions, as defined by the given IPO comments. Remember to include the IPO comments in your submission. Be sure to test your code -- you can use the examples given for each function, but you should probably test additional examples as well -- and then comment-out or remove your testing code from your submission!. We will be testing your functions using a separate program, and if your own testing code runs when we load your file it...

  • You will write Java programs in Eclipse to solve these word problems Read these instructions on...

    You will write Java programs in Eclipse to solve these word problems Read these instructions on how to name and submit the Java files. Please make sure your program compiles before you submit it. Make sure you name your Java file and class the same (otherwise it will not compile). For example, the class names are case-sensitive 1. will be in a file called CompareNames.java; remember, the Do not create a package. You can tell if your file is in...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development p...

    Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development practices and problem solving strategies: a) Start by writing the documentation for the function. Use docstrings shown in lecture and lab. b) Write test calls to the function in your main function for the different cases of input the function will encounter. This will help you understand the behavior of the function and later behave as tests for your function. c) Define the function d)...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

  • The following ANOVA model is for a multiple regression model with two independent variables: Degrees of            Sum of                 Mean Source           Freedom            Squares              ...

    The following ANOVA model is for a multiple regression model with two independent variables: Degrees of            Sum of                 Mean Source           Freedom            Squares                Squares       F       Regression            2                    60 Error                   18                 120 Total                   20                 180 Determine the Regression Mean Square (MSR): Determine the Mean Square Error (MSE): Compute the overall Fstat test statistic. Is the Fstat significant at the 0.05 level? A linear regression was run on auto sales relative to consumer income. The Regression Sum of Squares (SSR) was 360 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT