Java作业:
- 安装jdk。
答:
源代码:
public class Point {
public int x,y;
public Point(int x,int y) {
this.x=x;
this.y=y;
}
public Point() {
this(0,0);
}
public Point(Point p) {
this(p.x,p.y);
}
public String toString(){
return"("+this.x+","+this.y+")";
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Point point1=new Point();
Point point2=new Point(40,30);
System.out.println(new Line(point1,point2).toString());
}
}
class Line {
public Point point1,point2;
public Line(Point point1,Point point2) {
this.point1=point1;
this.point2=point2;
}
public double length(){
int a=point1.x-point2.x;
int b=point1.y-point2.y;
double x=a*a+b*b;
return Math.sqrt(x);
}
public String toString() {
return "一条直线,起点"+point1.toString()+"终点"+point2.toString()+"长度"+String.format("%102f", length());
}
}
- 安装集成开发环境eclipse进行调试代码。
姓名:谢云川 20173311129