To create a new Class A in package A, there is an int add (int m) method in Class A to seek 1+2+...+m
The and. In package B, create a new Class B, in Class B there is an int cheng (int n) method, used to seek n!
The result. Create a new main Class C in Package C, call the method in a, B to output 1+2+...+30 and,
and 5! Results of the calculation.
Package A;public Class A {//creates a new Class A in packet a, and in Class A has an int add (int m) method, which is used to seek the 1+2+...+m//. Create a new class B in package B, in Class B there is an int cheng (int n) method, which is used to find the result of n!//. Create a new main Class C in Package C, call the method in a, B to output 1+2+...+30,//and 5! Results of the calculation. int m; public int Getm () {return m;} public void Setm (int m) {this.m = m;} public int Add (int m) {int sum=0; for (int i=0;i<m;i++) { sum+=i; } return sum; }}
Package B;public Class B {//Creates a new class B in Pack B, and in Class B there is an int cheng (int n) method that is used to find the result of n!//. int n;public int getn () {return n;} public void Setn (int n) {THIS.N = n;} public int Cheng (int n) {int ji=1;for (int i=1;i<=n;i++) {ji*=i;} return ji;}}
Package C;import A.a;import B.b;public class C {public static void main (string[] args) {//TODO auto-generated method stub//Create a new main class C in packet C, call a , b the method output 1+2+...+30 and,//and 5! Results of the calculation. A a=new a (); A.setm (30); a.add; System.out.println (A.add (30)); b b=new B (); B.cheng (5); System.out.println (B.cheng (5));}}
Java Packages and access rights--3