0% found this document useful (0 votes)
60 views1 page

12 - MyMath Class

*** A user defined class ‘MyMath’ with various mathematical functions created by the user. Note that all functions are declared to be static and thus they can be directly qualified with the class name i.e. you can call fact function as MyMath.fact(23) public class MyMath { static int fact(int n){ int f=1; for(int i=1;i<=n;i++) f=f*i; return f; } static int findmax(int a,int b, int c){ int max; if(a>b && a>c) max=a; else if(b>a && b>c) max=b; else max=c; return max; } static int countdigits(long

Uploaded by

subhash varghese
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

12 - MyMath Class

*** A user defined class ‘MyMath’ with various mathematical functions created by the user. Note that all functions are declared to be static and thus they can be directly qualified with the class name i.e. you can call fact function as MyMath.fact(23) public class MyMath { static int fact(int n){ int f=1; for(int i=1;i<=n;i++) f=f*i; return f; } static int findmax(int a,int b, int c){ int max; if(a>b && a>c) max=a; else if(b>a && b>c) max=b; else max=c; return max; } static int countdigits(long

Uploaded by

subhash varghese
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

*** A user defined class ‘MyMath’ with various mathematical functions created by the user.

Note that all


functions are declared to be static and thus they can be directly qualified with the class name i.e. you can
call fact function as MyMath.fact(23)

public class MyMath {

static int fact(int n){


int f=1;
for(int i=1;i<=n;i++)
f=f*i;
return f;
}

static int findmax(int a,int b, int c){


int max;

if(a>b && a>c)


max=a;
else if(b>a && b>c)
max=b;
else
max=c;

return max;
}

static int countdigits(long n){


int c=0;

while(n>0){
c=c+1;
n=n/10;
}
return c;
}

static long reversedigits(long n){


int c=0;
long temp=0;

while(n>0){
temp=(temp*10)+(n%10);
n=n/10;
}
return temp;
}

static long adddigits(long n){


long sum=0;

while(n>0){
sum=sum+(n%10);
n=n/10;
}
return sum;
}

} // end class

You might also like