1. java紼嬪簭棰橈細鍒涘緩涓夎掑艦綾籘riangle
publicclassTriangle{
/*
*•鍒涘緩涓夎掑艦綾籘riangle錛岃ョ被鍖呮嫭錛涓変釜鍚嶄負side1,side2,side3鐨刣ouble鏁版嵁鍩熼粯璁ゅ1.0;
*涓涓鏃犲弬鏋勯犳柟娉曪紝鍒涘緩榛樿ょ殑涓夎掑艦錛涓涓猻ide1,side2,side3鎸囧畾鍊肩殑鏋勯犳柟娉涓変釜鏁版嵁鍩熺殑璁塊棶鍣ㄥ拰淇鏀瑰櫒錛鍚嶄負getArea(
*)鐨勬柟娉曪紝榪斿洖涓夎掑艦鐨勯潰縐錛鍚嶄負getPerimeter()鐨勬柟娉曪紝榪斿洖涓夎掑艦鐨勫懆闀匡紱
*鍚嶄負toString鐨勬柟娉曪紝榪斿洖涓夎掑艦鐨勫瓧絎︿覆錛宺eturn"Triangle:side1="+side1+
*"side2="+side2+"side3="+side3;
*/
privatedoubleside1=10;
privatedoubleside2=10;
privatedoubleside3=10;
publicdoublegetArea(){
return(side1+side2+side3)/2;
}
publicdoublegetPerimeter(){
returnside1+side2+side3;
}
publicStringtoString(){
return"Triangle:side1="+side1+"side2="+side2+"side3="
+side3;
}
/**
*@Description:Triangle鏋勯犲嚱鏁
*/
publicTriangle(){
}
publicdoublegetSide1(){
returnside1;
}
publicvoidsetSide1(doubleside1){
this.side1=side1;
}
publicdoublegetSide2(){
returnside2;
}
publicvoidsetSide2(doubleside2){
this.side2=side2;
}
publicdoublegetSide3(){
returnside3;
}
publicvoidsetSide3(doubleside3){
this.side3=side3;
}
}
2. 鐢╦ava紼嬪簭鍐欎竴涓涓夎掑艦
public class DaoSanJiao { // 瀹氫箟涓涓鍊掍笁瑙掔殑綾伙紝鏈変富鏂規硶鍜 杈撳嚭鍊絳夎叞涓夎掑艦鏂規硶
public static void main(String[] args) { // 瀹氫箟涓繪柟娉曪紝紼嬪簭浠庤繖閲屽紑濮
printDengyao(10); // 璋冪敤杈撳嚭鍊掍笁瑙掑艦鐨勬柟娉曪紝*鏁頒負10錛 鍗抽珮搴︼紙灞傦級涔熶負10
// 10鍙浠ユ崲鎴愪換浣鏁村瀷鍊
}
public static void printDengyao(int x) { // 瀹氫箟涓涓杈撳嚭鍊掍笁瑙掔殑鏂規硶
for (int i = 0; i < x; i++) { // 瑕佽緭鍑虹殑鏁翠綋錛堝叏閮ㄥ氬皯琛岋級鐢ㄨ繖涓for寰鐜鎺у埗
System.out.println(); // 杈撳嚭涓琛*鍚庤煩鍒頒笅涓琛
for (int j = 0; j < i + 1; j++) { // 榪欎釜寰鐜鐢ㄦ潵杈撳嚭絀烘牸錛屼互杈懼埌杈撳嚭鍊掔瓑鑵頒笁瑙掑艦鐨勬晥鏋
System.out.print(" ");
}
for (int j = i; j < x; j++) { // 榪欎釜寰鐜鐢ㄦ潵杈撳嚭*錛屼粬鐨勬暟鐩鏈変紶鍏ョ殑鍙傛暟x鍐沖畾
System.out.print("* "); // 濡傦細i=0鏃跺嵆絎涓琛岋紝杈撳嚭x涓鈥*鈥
}
}
}
}