十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
package com;
成都创新互联专注于企业营销型网站、网站重做改版、曾都网站定制设计、自适应品牌网站建设、H5场景定制、商城网站定制开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为曾都等各大城市提供网站开发制作服务。
import java.awt.Point;
public class JuLi {
public static void main(String[] args) {
Point p1 = new Point(5, 5);// 定义第一个点的坐标(5,5),或者你自己设置x,y坐标
Point p2 = new Point(6,6);// 定义第一个点的坐标(5,5),或者你自己设置x,y坐标
// 两点间距离
double jili = Math.sqrt(Math.abs((p1.getX() - p2.getX())
* (p1.getX() - p2.getX())+(p1.getY() - p2.getY())
* (p1.getY() - p2.getY())));
System.out.println("两点间的距离是:" + jili);
}
}
题目是要求写出类Point吗?是的话代码如下:
public class Point{
private int x;
private int y;
public Point(int x,int y){
this.x = x;
this.y = y;
}
public double ppdistance(Point p){
return Math.sqrt(Math.pow(x - p.getX(),2)+Math.pow(y - p.getY(),2));
}
public Point move(int x,int y){
return new Point(this.x + x,this.y + y);
}
public String toString(){
return "("+x+","+y+")";
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
btw:类名一般是首字母大写。出题人不严谨!
java调整字符间距Font f =new Font("宋体",Font.BOLD,20);
如果是css就用下面的代码
html
head
style type="text/css"
p.spread {word-spacing: 30px;}
p.tight {word-spacing: -0.5em;}
/style
/head
body
p class="spread"This is some text. This is some text./p
p class="tight"This is some text. This is some text./p
/body
/html
import java.util.Scanner;
public class Demo
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
Point p1,p2;
System.out.println("请输入第1个点的x、y坐标:");
p1=new Point(sc.nextDouble(),sc.nextDouble());
System.out.println("请输入第2个点的x、y坐标:");
p2=new Point(sc.nextDouble(),sc.nextDouble());
System.out.println("点"+p1+"与点"+p2+"的距离是"+p1.distance(p2));
}
}
class Point
{
Point(double x,double y)
{
this.x=x;
this.y=y;
}
public String toString()
{
return "("+x+","+y+")";
}
double distance(Point p)
{
return Math.sqrt(Math.pow(this.x-p.x,2)+Math.pow(this.y-p.y,2));
}
private double x,y;
}