Results 1 to 4 of 4

Thread: Help with function calls (resolved)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    Help with function calls (resolved)

    Never had java before so i need some help. This is for a homework assignment.
    I got 3 function prototypes: 1. int pow(int int)
    2. double pow(double double)
    3. double pow(int double)
    int x;
    double y;
    x=pow(2,3)
    y=pow(2,3)
    x=pow(2,3.2)
    y=pow(2,3.2)
    x=pow(2.1,3)
    y=pow(2.1,3)
    x=pow(2.1,3.2)
    y=pow(2.1,3.2)

    I want to know for every pow call what function is called or is it illegal?
    in c++ i got {1,1,3,3,illegal,illegal,2,2}
    Never had java any tips on how java works?
    Last edited by abcdefg; Mar 16th, 2004 at 01:53 PM.

  2. #2
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104

    Re: Help with function calls

    Originally posted by abcdefg
    Never had java before so i need some help. This is for a homework assignment.
    I got 3 function prototypes: 1. int pow(int int)
    2. double pow(double double)
    3. double pow(int double)
    int x;
    double y;
    x=pow(2,3) <-- ok
    y=pow(2,3) <-- ok
    x=pow(2,3.2) <-- not ok
    y=pow(2,3.2) <-- ok
    x=pow(2.1,3) <-- not ok
    y=pow(2.1,3) <-- ok
    x=pow(2.1,3.2) <-- not ok
    y=pow(2.1,3.2) <-- ok

    I want to know for every pow call what function is called or is it illegal?
    in c++ i got {1,1,3,3,illegal,illegal,2,2}
    Never had java any tips on how java works?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    java function calls

    thanx for tha help i had no clue book was worthless

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Unless the narrowing conversions are made explicit(as they have to be since there is no implicit narrowing conversions in Java only implicit widing conversions) your code will fail to compile. Without the int pow(int i, int k) method the first call in red has to have an explicit type conversion since bolth methods return a double.
    Code:
     public class X{
       public static void main(String[] args){
    
       int x;
       double y;
       x=(int)pow(2,3); //possible loss of precision
       y=pow(2,3);
       x=(int)pow(2,3.2); //possible loss of precision
       y=pow(2,3.2);
       x=(int)pow(2.1,3); //possible loss of precision
       y=pow(2.1,3);
       x=(int)pow(2.1,3.2); //possible loss of precision
       y=pow(2.1,3.2);
    
     }
    
     public static double pow(double x, double y){
       return Math.pow(x,y);
      }
    
      public static double pow(int q, double s){
       return Math.pow(q,s);
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width