public class sum { int sum = 0; int fum = 1; int n; public sum(int m) { n = m; } public void Countsum() { //求和 for(int i = 1;i <= n; ++ i) { sum += i; } } public void Countfum() {//求阶乘 for(int i = 1;i <= n;++i) { fum *= i; } } public static void main(String []args) { sum s=new sum(5); s.Countsum(); s.Countfum(); System.out.println("1 + 2 + 3 +...+" + s.n + "= " + s.sum); System.out.println(s.n+"!=" + s.fum); } }