我寫了下面的程序:爲什麼我不能打印價值?
import java.util.Scanner ;
public class Triangle
{
public static void main (String [] args)
{
Scanner scan = new Scanner (System.in) ; // new object named "scan"
// Next lines scan ribs values into a,b,c parameters
System.out.println ("Please enter first rib value : " ) ;
int a = scan.nextInt() ;
System.out.println ("Please enter second rib value : " ) ;
int b = scan.nextInt() ;
System.out.println ("Please enter third rib value : " ) ;
int c = scan.nextInt() ;
if (! ((a >= 1) && (b>=1) && (c>=1)))
System.out.println ("One or more of the ribs value is negative !!\nPlease enter a positive value ONLY ! " ) ;
else if (! ((a <= b+c) && (b <= a+c) && (c <= a+b)))
System.out.println ("Error !\n\nOne rib can not be bigger than the two others ! " ) ;
else
{
float s = (a+b+c)/2 ;
double area = Math.sqrt(s * (s-a) * (s-b) * (s-c)) ;
float perimeter = s*2 ;
System.out.println ("Perimeter of the triangle is: "+perimeter+"\n\nArea of the triangle is: "+area) ;
}// end of else
}//end of method main
} //end of class Triangle
的問題是,我在屏幕上得到區域值0.0爲三角形的肋骨的每一個法律價值。
這是爲什麼?我做了一切似乎是好的..不是嗎?!
日Thnx
對於輸入2,2,2我得到了'三角形的周長是:6.0 三角形的面積是:1.7320508075688772' – 2011-02-28 19:57:02