/*定义一个计算器实现加减乘除累加阶乘求平方次方并判断是否是素数public class Cal { public int jia(int a,int b){ int sum=a+b; return sum; } public int jian(int a,int b){ int jian=a-b; return jian; } public int cheng(int a,int b){ int cheng=a*b; return cheng; } public float chu(int a,int b){ float chu=a/b; return chu; } public void leijia(int a){ int s=0; for(int i=1;i<=a;i++){ s=s+i; } System.out.println("累加的结果是:"+s); } public void jiecheng(int a){ int z=1; for (int i =1;i<=a; i++) { z=z*i; } System.out.println("阶乘的结果是:"+z);} public int ping(int a){ a=a*a; return a; } public int ci(int a){ a=a*a*a; return a; } public boolean su(int a){ boolean flag = true; if (a < 2) { return false; } else { for (int i = 2; i <= a; i++) { if (a % i == 0) { flag = false; break; } } } return flag; } }
public class Test{ public static void main(String[] args) { Cal c=new Cal(); int a=5; int b=2; int sum=c.jia(a, b); System.out.println(sum); System.out.println(c.jian(a, b)); System.out.println(c.cheng(a, b)); System.out.println(c.chu(a, b)); c.leijia(a); c.jiecheng(a); System.out.println(c.ping(a)); System.out.println(c.ci(a)); System.out.println(c.su(a)); } }
时间: 2024-09-30 07:37:00