Java---定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)
生活随笔
收集整理的这篇文章主要介绍了
Java---定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
要求如下:
源代码如下:
import java.util.Scanner;public class Point {private int x;//x坐标private int y;//y坐标private int z;//z坐标public Point(int x,int y, int z) {this.x = x;this.y = y;this.z = z;}void showPoint(){//显示点坐标System.out.print("点的坐标为: ");System.out.println("(" + x + "," + y + "," + z + ")");}void squareOfDistance(){//计算距离原点的平方System.out.print("该点距离原点的平方为: ");System.out.println(x*x + y*y + z*z);}public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.print("请输入点的x,y,z坐标: ");Scanner in = new Scanner(System.in);//键盘输入Point point1 = new Point(in.nextInt(),in.nextInt(),in.nextInt());point1.showPoint();point1.squareOfDistance();in.close();} }总结
以上是生活随笔为你收集整理的Java---定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Java---中国有句俗语叫“三天打鱼两
- 下一篇: Java---定义一个圆(Circle)