Computer problems,Computer help
*AX SOFT>>>Programming & Design

Hi i need help with JAVA , can anyone help?


hi i am doing some Homework and i am having trouble with this question
the Q is :
Write the definition of a method powerTo , which receives two parameters. The first is a double and the second is an int . The method returns a double .
If the second parameter is negative, the method returns zero. Otherwise it returns the value of the first parameter raised to the power of the second.

what i have is :

public double powerTo(double d, int i){
return d;
if(i<0){
b = 0.0;}
else{Math.pow(d, i);}
}

can any one help

public double powerTo(double d, int i){

double temp;

if(i<0)
temp = 0.0;
else
temp = Math.pow(d,i);

return temp;

}

Its been a couple semester since I took Java but four problems I see right away are:

1. the return statement should always be last
2. the variable b is not declared.
3. The math.Pow method requires 2 doubles
4. You need to assign the Math.pow to a variable. Somthing simliar to b = Math.pow(d1, d2)

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Help with website??

    Setting up a Web site is very easy and if you want to do it for free just go to ...

  • How to Write a C program with a loop that asks user to enter a series of integers in the range of [-100 100].?

    Your loop will be a while loop anwer = -999; while (answer!=0) { ask user for answer if(answer<100 and answer>-100) { if(answer<smallest) smallest = answer if(answer>largest)...

  • Whats wrong with my code?

    This line is illegal: int 1=1,n,f; as "int" is used to declare a variable of type integer. You could always try saying int one = 1; int f; but I have no idea what the n is doing th...

  • I just moved my asp.net app. project over the devlopment server but having issue with login. unable to loging?

    What kind of authentication are you using? Windows authentication? Forms authentication? A custom solution? I'm lead to believe that perhaps you're using Windows authentication, and th...

  • How can a computer be random?

    hehe, good question. The answer is it can't. In the absence of this, 'pseudorandom' is good enough. If it appears random to us, what's the difference? A common technique use...

  • How do i enable java script on my laptop?

    In firefox you go to tools options content. Then click the check box next to enable java script. In internet explorer you go to tools internet options then click the security tab, set your own cust...

  • What u say about it...???

    Very nice. You will be a successful web designer when you finish school. As the other said, the content has bad spelling and grammar which should be reviewed.

    ...
  • I want visitors to be able to post comments on my webpage and have other visitors view them, is there a way?

    ...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster