一.
import java.util.Scanner; class dis{ public void distance(double a,double b,double m,double n) { System.out.println("两点之间的距离为:"+Math.sqrt((a-m)*(a-m)+(b-n)*(b-n))); } } public class Pointa { double a,b; public void set(double k,double f) { a=k; b=f; } public double get_a() { return a; } public double get_b() { return b; } public static void main(String []args) { Pointa []k=new Pointa[2]; Scanner input=new Scanner(System.in); double []l=new double[4]; for(int i=0;i<4;i++) { l[i]=input.nextDouble(); } k[0]=new Pointa(); k[1]=new Pointa(); k[0].set(l[0],l[1]); k[1].set(l[2],l[3]); dis o=new dis(); o.distance(k[0].get_a(), k[0].get_b(), k[1].get_a(), k[1].get_b()); } }
java中没有友元的概念
//Test1.java
package test;
class Test1 {}
//Test2.java
package test;
public class Test2 {
public static void main(String[] args) {
Test1 t;
}
}
二.在class中使用本类未成功
三.例题