導航:首頁 > 編程語言 > java點類

java點類

發布時間:2023-06-05 21:31:21

java定義一個點類Point, 具備坐標系中的橫坐標x, 和縱坐標y, 並實現如下功能:

Point類


publicclassPoint{
privatefloatx;
privatefloaty;
publicPoint(floatx,floaty){
this.x=x;
this.y=y;
}

publicfloatgetX(){
returnx;
}

publicvoidsetX(floatx){
this.x=x;
}

publicfloatgetY(){
returny;
}

publicvoidsetY(floaty){
this.y=y;
}

publicfloatdistanceToOrigin(){
return(float)Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2));
}

publicfloatdistanceToOther(intx,inty){
return(float)Math.sqrt(Math.pow(this.x-x,2)+Math.pow(this.y-y,2));
}

publicfloatdistanceToOther(Pointpoint){
return(float)Math.sqrt(Math.pow(this.x-point.x,2)+Math.pow(this.y-point.y,2));
}
}

測試類

publicclassTestPoint{
publicstaticvoidmain(String[]args){
Pointp1=newPoint(3,5);
Pointp2=newPoint(7,8);
System.out.println(p1.distanceToOrigin());
System.out.println(p2.distanceToOrigin());
System.out.println(p1.distanceToOther(20,30));
System.out.println(p2.distanceToOther(20,30));
System.out.println(p1.distanceToOther(p2));
}
}
閱讀全文

與java點類相關的資料

熱點內容
解壓後文件夾里的內容丟失 瀏覽:713
解壓無敵視頻 瀏覽:688
什麼是伺服器辨認不了 瀏覽:126
java如何調用類方法 瀏覽:481
管理孩子的app叫什麼 瀏覽:544
壓縮活動軌跡 瀏覽:674
6米梁加密筋 瀏覽:79
怎麼學好ps如何學好編程 瀏覽:300
c編譯器廠商 瀏覽:114
簡述編譯程序以及解釋程序 瀏覽:3
linux升級kernel 瀏覽:176
入侵伺服器挖礦是什麼罪 瀏覽:47
房屋解壓資料丟了怎麼辦 瀏覽:810
java文件行讀寫 瀏覽:544
影城網上售票系統源碼 瀏覽:634
防疫就是命令歌曲 瀏覽:204
滴滴號碼加密怎麼解除 瀏覽:844
模具編程的職責 瀏覽:944
華為ssh改加密演算法 瀏覽:149
文件夾空白合同 瀏覽:763