answersLogoWhite

0


Best Answer

In practice, it is better to use the Math class, which already has a pow() (i.e., power) function. If you want to program it yourself, just write a loop:

double myPower(double x, int y)
{
double result = 1;
for (int i = 1; i <= y; i++)
result *= x;

return result;

}

For overloading, simply repeat with different arguments. You might also re-use the method created previously, like this:

int myPower(int x, int y) {return (int) myPower(x, y) }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: 1 Write a Java program to find x to the power y Use overloading for different cases when x and y are combination of integer and floating point numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When do you need to use default arguments in a function?

We declare (not use) default arguments in a function whenever the default values cover the majority of calls to that function. We use default arguments in order to simplify those calls and thus reduce the verbosity of our calling code, thus making it easier to call the function.


What is function overloading in c language of computer?

There is no such thing as function overloading in C; that is a feature of C++. Function overloading allows us to provide two or more implementations of the same function. Typically, we use function overloading so that the same function can cater for different types. For instance, we might provide one implementation that is optimised to handle an integer argument while another is optimised to handle a real argument. We can also use function overloading to provide a common implementation of a function which can then be invoked by overloads that handle the low-level type conversions.


What is a floating number?

A floating point number is one that contains an integer as well as a fractional part, for example 101.3625. These are often represented by their scientific notations as well, such as 1.013625E2


What are advantages and disadvantages of Integer programming?

The advantages of integer arithmetic over floating point arithmetic is the absence of rounding errors. Rounding errors are an intrinsic aspect of floating point arithmetic, with the result that two or more floating point values cannot be compared for equality or inequality (or with other relational operators), as the exact same original value may be presented slightly differently by two or more floating point variables. Integer arithmetic does not show this symptom, and allows for simple and reliable comparison of numbers. However, the disadvantage of integer arithmetic is the limited value range. While scaled arithmetic (also known as fixed point arithmetic) allows for integer-based computation with a finite number of decimals, the total value range of a floating point variable is much larger. For example, a signed 32-bit integer variable can take values in the range -231..+231-1 (-2147483648..+2147483647), an IEEE 754 single precision floating point variable covers a value range of +/- 3.4028234 * 1038 in the same 32 bits.


What are 3 different data types?

According to Wikipedia,"In computer science and computer programming, a data type or simply type is a classification identifying one of various types of data, such as real-valued, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.""Almost all programming languages explicitly include the notion of data type, though different languages may use different terminology. Common data types may include:integers,booleans,characters,floating-point numbers,alphanumeric strings."

Related questions

When do you need to use default arguments in a function?

We declare (not use) default arguments in a function whenever the default values cover the majority of calls to that function. We use default arguments in order to simplify those calls and thus reduce the verbosity of our calling code, thus making it easier to call the function.


What is function overloading in c language of computer?

There is no such thing as function overloading in C; that is a feature of C++. Function overloading allows us to provide two or more implementations of the same function. Typically, we use function overloading so that the same function can cater for different types. For instance, we might provide one implementation that is optimised to handle an integer argument while another is optimised to handle a real argument. We can also use function overloading to provide a common implementation of a function which can then be invoked by overloads that handle the low-level type conversions.


Explain different types of constant?

Integer constants Character constants Real/floating point constants String constants


What is the largest integer and the largest floating-point number?

In real-world math, there is no "largest" integer or floating point number. This is covered by the concepts known as "infinity" and "irrationality." Depending on the processor and/or application, a number with significant digits into the thousands can be operated upon.


What makes an integer different?

Each integer is different from every other integer since it represents a different quantity. Actually, this is true of every number.


What is a floating number?

A floating point number is one that contains an integer as well as a fractional part, for example 101.3625. These are often represented by their scientific notations as well, such as 1.013625E2


Is 9.6 and integer?

No, 9.6 is a floating-point number. Integers are whole numbers without fractional parts.


What are advantages and disadvantages of Integer programming?

The advantages of integer arithmetic over floating point arithmetic is the absence of rounding errors. Rounding errors are an intrinsic aspect of floating point arithmetic, with the result that two or more floating point values cannot be compared for equality or inequality (or with other relational operators), as the exact same original value may be presented slightly differently by two or more floating point variables. Integer arithmetic does not show this symptom, and allows for simple and reliable comparison of numbers. However, the disadvantage of integer arithmetic is the limited value range. While scaled arithmetic (also known as fixed point arithmetic) allows for integer-based computation with a finite number of decimals, the total value range of a floating point variable is much larger. For example, a signed 32-bit integer variable can take values in the range -231..+231-1 (-2147483648..+2147483647), an IEEE 754 single precision floating point variable covers a value range of +/- 3.4028234 * 1038 in the same 32 bits.


A quantity that can be equal to any integer and can take any different integer values is known as?

Integer variables


How can the decimal real number 175.23 be represented as a 6 digit integer in floating point notation?

175.23*10^-2


How can the decimal real number 1385.58 be represented as a 6-digit integer in floating point notation?

138558 x 10-2


How is a rational number that is not an integer different from a rational number that is an integer?

A rational number which is an integer can be simplified to a form in which the denominator is 1. That is not possible for a rational number which is not an integer.