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涓鈥*鈥
}
}
}
}