Question

Write a method public double square(double x) that computes the square of the parameter x.

Write a method

public double square(double x)

that computes the square of the parameter x.

Homework Answers

Answer #1

public double square(double x) {
    return x * x;
}

import java.util.Scanner;

public class SquareNumber {

    public double square(double x) {
        return x * x;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a number: ");
        System.out.println("Square: " + new SquareNumber().square(in.nextDouble()));
    }
}

Know the answer?
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
Similar Questions
Write a recursive method that computes the value of x^n
Write a recursive method that computes the value of x^n
write a method named area with one double parameter named radius. The method needs to return...
write a method named area with one double parameter named radius. The method needs to return a double value that represents the area of a circle. If the parameter radius is negative, Then return -1.0 to represent an invalid value write another overloaded method with 2 parameters side1 and side2 (both doubles) where side1 and side2 represent the sides of a rectangle. The method needs to return an area of a rectangle. If either or both parameters is /are a...
Write a recursive method that computes the value of xn.
Write a recursive method that computes the value of xn.
public static int newtonCount​(double x, double err) Determines the number of iterations of Newton's method required...
public static int newtonCount​(double x, double err) Determines the number of iterations of Newton's method required to approximate the square root of x within the given bound. Newton's method starts out by setting the initial approximate answer to x. Then in each iteration, answer is replaced by the quantity (answer + x / answer) / 2.0. The process stops when the difference between x and (answer * answer) is strictly less than the given bound err. The method returns the...
Python: Write a function that takes in a number as a parameter and calculates the square...
Python: Write a function that takes in a number as a parameter and calculates the square of the number up to and including the value of the parameter. Please use a while or for loop.
PYTHON: Write a function that takes in a number as a parameter and calculates the square...
PYTHON: Write a function that takes in a number as a parameter and calculates the square of the number up to and including the value of the parameter. The function must perform the process recursively.
JAVA coding language: Complete the howFast method that take a double parameter, speed, and prints a...
JAVA coding language: Complete the howFast method that take a double parameter, speed, and prints a message based on the value of speed. These are the message that should be printed for each range of values for speed: "slow" for values of speed less than or equal to 10. "fast" for values of speed greater than 10 and strictly less than or equal to 50. "very fast" for values of speed greater than 50 and strictly less than or equal...
Given class Function {     public:     virtual double compute(double value) = 0;     virtual double differentiate(double value) =...
Given class Function {     public:     virtual double compute(double value) = 0;     virtual double differentiate(double value) = 0;     virtual double integrate(double value) = 0; }; class Sine : public Function {     public:     double compute(double value); // compute sin(x) for a given x     double differentiate(double value); // compute derivative sin'(x) for a given x     double integrate(double value); // integrate sin(x) for a given x }; class Tangent : public Function {     public:     double compute(double value); // compute tan(x) for a given x...
Write a MatLab function J = Jcb(f, x) that computes the jacobian of the vector f...
Write a MatLab function J = Jcb(f, x) that computes the jacobian of the vector f of functions of x. Input f is the vector of functions [f1(x1, x2, x3...); f2(x1, x2, x3...); ...] and inout x is a vector of unkown x [x1; x2; x3;...]. Output J is the jacobian square matrix of vector f.
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all...
Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT