同名異式的方法public class OverLoading { public static void main(String[] args) { double a,b,c,d,h; a=10.0; b=8.0; c=15.0; d=30.0; h=20.0; System.out.println("以三個邊長求三角型面積"); System.out.println("a="+a+"b="+b+"c="+c+"->S="+triangle(a,b,c)); System.out.println("底="+d+"高="+h+"->S="+triangle(d,h)); } static double triangle (double a,double b,double c) { double s,temp,ss; s=(a+b+c)/2; temp=s*(s-a)*(s-b)*(s-c); ss=Math.sqrt(temp); return ss; } static double triangle (double d,double h) { double ss; ss=(d*h)/2; return ss; }} .msgcontent .wsharing ul li { text-indent: 0; } 分享 Facebook Plurk YAHOO! .


rr22278 發表在 痞客邦 留言(0) 人氣()