日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java---定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)

發布時間:2025/5/22 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)类用来表示三维空间中的点(有三个坐标)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。