## gahhon 13 Junior Poster

is possible to work of return statement with Math Class?
eg,

``return Math.pow(2,2);``

## Taywin 312

Yes, but you need to return the correct type. I think it is double.

## mKorbel 274

I think the @Taywin meaning

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

couldn't you do

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

Yes, you could.

## gahhon 13

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

## NP-complete 42

@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...:)

## gahhon 13

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

## JamesCherrill 4,219

Math.pow returns a double, but you can convert that to an int in your method and return the int, if that's what you want.

## gahhon 13

but how to convert directly from method?

## JamesCherrill 4,219

Sorry, don't understand that question. Can you be more explicit?

## gahhon 13

which mean how can i convert to int in my method??

## JamesCherrill 4,219

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;``````

## gahhon 13

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

``public static int convert(double x, double y)``

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

## JamesCherrill 4,219

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

## gahhon 13

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

## JamesCherrill 4,219

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.

## gahhon 13

oh okay thank you dude. :)