is possible to work of return statement with Math Class?

eg,

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

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

Jump to PostI think the @Taywin meaning

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

Jump to Postcouldn't you do

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

Jump to PostYes, you could.

Jump to Post@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):

Taywin
312
Posting Virtuoso

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

mKorbel
274
Veteran Poster

I think the @Taywin meaning

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

Edited
by mKorbel because:
*
n/a *

sirlink99
56
Practically a Master Poster

couldn't you do

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

Taywin
312
Posting Virtuoso

Yes, you could.

gahhon
13
Junior Poster

because tutorial question require to do an expression with return a power. :(

NP-complete
42
Junior Poster

@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
by NP-complete because:
*
n/a *

gahhon
13
Junior Poster

oh, but why must be in double, cannot be integer type?

nowander i can't work with integer type.

JamesCherrill
4,577
Most Valuable Poster
Moderator
Featured Poster

gahhon
13
Junior Poster

but how to convert directly from method?

JamesCherrill
4,577
Most Valuable Poster
Moderator
Featured Poster

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

gahhon
13
Junior Poster

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

JamesCherrill
4,577
Most Valuable Poster
Moderator
Featured Poster

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
by JamesCherrill because:
*
n/a *

gahhon
13
Junior Poster

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

JamesCherrill
4,577
Most Valuable Poster
Moderator
Featured Poster

*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
Junior Poster

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

JamesCherrill
4,577
Most Valuable Poster
Moderator
Featured Poster

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
Junior Poster

oh okay thank you dude. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.

Broken Link

**You're trying to visit a URL that doesn't currently exist on the web.**
Most likely, a member posted a link a long time ago to a web page that has since been removed.
It's also possible that there was a typo when posting the URL.
We redirect you to this notice instead of stripping out the link to preserve the integrity of the post.