is possible to work of return statement with Math Class?

return Math.pow(2,2);

Edited 5 Years Ago by gahhon: n/a

I think the @Taywin meaning

Double myCalculation (double first, double second) {
   double someDouble = Math.pow(first, second);
   return someDouble;

Edited 5 Years Ago by mKorbel: n/a

couldn't you do

public double (double number1, double number2){
return (Math.pow(number1, number2));

but what if i just want return it inside the return statement?
because tutorial question require to do an expression with return a power. :(

@gahhon: I think the above examples, specially that of sirlink99's (maybe he forgot to give a name to his method) did exactly that...or maybe i don't understand your question...

In case you didn't understand sirlink99's example, here's it once again (with a method name, this time):

public double myPow(double number1, double number2) {
    return Math.pow(number1, number2);

The braces around the ((Math.pow(...)) is not necessary; don't know if they were confusing you...:)

Edited 5 Years Ago by NP-complete: n/a

oh, but why must be in double, cannot be integer type?
nowander i can't work with integer type.

Here's an example of casting a double to int. You can use the same technique in your method

double d = 12.3;
int i = (int) d;

Edited 5 Years Ago by JamesCherrill: n/a

return (int)Math.pow(3,2);

this is working but how about this

public static int convert(double x, double y)

is possible to convert it to integer type, when return?

convert what to int?
you pass in two doubles and return one int. What is the relationship between the doubles and the returned value?

i am trying to ask is the double x and double y possible to convert into Int inside the bracket?

You can convert any double to an int anywhere you want by casting it (like in my previous example).
ps: A double can store values that have more precision than an int, or are larger than the largest possible int, so it's up to you to think about what the values are going to be and what result you expect from converting them.

This question has already been answered. Start a new discussion instead.