C:\DATA\Java2\Dos>java Heron l1=3.0 l2=4.0 l3=5.0 面積=6.0 l1=1.0 l2=2.0 l3=1.7320508075688772 面積=0.866025403784438 -- Press any key to exit (Input "c" to continue) -- |
class Heron { public static void main(String args[]) { double l1,l2,l3,p,s; l1= 3; l2= 4; l3= 5; p= (l1+l2+l3)/2; s= Math.sqrt(p*(p-l1)*(p-l2)*(p-l3)); System.out.print("l1=" + l1 + " l2=" + l2 + " l3=" + l3); System.out.println(" 面積=" + s); l1= 1; l2= 2; l3= Math.sqrt(3); p= (l1+l2+l3)/2; s= Math.sqrt(p*(p-l1)*(p-l2)*(p-l3)); System.out.print("l1=" + l1 + " l2=" + l2 + " l3=" + l3); System.out.println(" 面積=" + s); } } |
l1= 3; l2= 4; l3= 5; |
p= (l1+l2+l3)/2; s= Math.sqrt(p*(p-l1)*(p-l2)*(p-l3)); System.out.print("l1=" + l1 + " l2=" + l2 + " l3=" + l3); System.out.println(" 面積=" + s); |
l1= 1; l2= 2; l3= Math.sqrt(3); |
p= (l1+l2+l3)/2; s= Math.sqrt(p*(p-l1)*(p-l2)*(p-l3)); System.out.print("l1=" + l1 + " l2=" + l2 + " l3=" + l3); System.out.println(" 面積=" + s); } |