定义一个接口,接口中有两个抽象的方法:long factorial(int m);求参数的阶乘。long myPower(int m,int n)
接口中有两个抽象的方法:longfactorial(intm);求参数的阶乘。longmyPower(intm,intn);求参数m的n次方。booleanfindFac...
接口中有两个抽象的方法:long factorial(int m);求参数的阶乘。long myPower(int m,int n);求参数m的n次方。boolean findFactorSum(int m,int n);判断参数中较小数是否是较大数的因子。实现该接口
展开
3个回答
展开全部
interface Test{
long factorial(int m);
long myPower(int m,int n);
boolean findFactorSun(int m,int n);
}
class Fa implements Test{
public int Fm=1;
public long factorial(int m){
for(int i=1;i<=m;i++){
Fm*=i;
}
return Fm;
}
public long myPower(int m,int n){
if(n==1)
return m;
else
return myPower(m,n-1)*m;
}
public boolean findFactorSun(int m,int n){
return m>=n? m%n==0?true:false:n%m==0?true:false;
}
}
public class First {
public static void main(String[] args) {
Fa f=new Fa();
System.out.println("M的阶乘为:"+f.factorial(8));
System.out.println("m的n次方为:"+f.myPower(8, 4));
System.out.println("参数中较小数是否是较大数的因子:"+f.findFactorSun(4, 8));
}
long factorial(int m);
long myPower(int m,int n);
boolean findFactorSun(int m,int n);
}
class Fa implements Test{
public int Fm=1;
public long factorial(int m){
for(int i=1;i<=m;i++){
Fm*=i;
}
return Fm;
}
public long myPower(int m,int n){
if(n==1)
return m;
else
return myPower(m,n-1)*m;
}
public boolean findFactorSun(int m,int n){
return m>=n? m%n==0?true:false:n%m==0?true:false;
}
}
public class First {
public static void main(String[] args) {
Fa f=new Fa();
System.out.println("M的阶乘为:"+f.factorial(8));
System.out.println("m的n次方为:"+f.myPower(8, 4));
System.out.println("参数中较小数是否是较大数的因子:"+f.findFactorSun(4, 8));
}
展开全部
import java.io.InputStream;
import java.util.Scanner;
public class TestSum
{
public static void main(String[] args)
{
InputStream is = System.in;
Scanner scan = new Scanner(is);
System.out.print("请输入一个整数:");
int num = scan.nextInt();
System.out.println(num+"的阶乘为:"+factorial(num));
System.out.println(num+"的2次方为:"+myPower(num,2));
System.out.println(num+"与2次,小者是否为大的因子:"+findFactorSum(num,2));
}
public static long factorial(int m){
int flag = m >=0 ? 1 : -1;
long result = 1;
for(int i=2;i<=Math.abs(m);i++){
result *= i;
}
return Math.pow(flag,Math.abs(m)) > 0 ? result : 0-result;
}
public static long myPower(int m,int n){
return ((Double)Math.pow(m,n)).longValue();
}
public static boolean findFactorSum(int m,int n){
return m>=n ? m%n == 0 ? true : false : n%m == 0 ? true :false;
}
}
import java.util.Scanner;
public class TestSum
{
public static void main(String[] args)
{
InputStream is = System.in;
Scanner scan = new Scanner(is);
System.out.print("请输入一个整数:");
int num = scan.nextInt();
System.out.println(num+"的阶乘为:"+factorial(num));
System.out.println(num+"的2次方为:"+myPower(num,2));
System.out.println(num+"与2次,小者是否为大的因子:"+findFactorSum(num,2));
}
public static long factorial(int m){
int flag = m >=0 ? 1 : -1;
long result = 1;
for(int i=2;i<=Math.abs(m);i++){
result *= i;
}
return Math.pow(flag,Math.abs(m)) > 0 ? result : 0-result;
}
public static long myPower(int m,int n){
return ((Double)Math.pow(m,n)).longValue();
}
public static boolean findFactorSum(int m,int n){
return m>=n ? m%n == 0 ? true : false : n%m == 0 ? true :false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-05-04
展开全部
自己到图书馆有许多这方面的介绍
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询