import javax.swing.JOptionPane;
 public class sanjiaoxing{
  public static void main(String[] s)
 {  int a=0,b=0,c=0;
    String bian1=JOptionPane.showInputDialog(null,"Enter a number","输入其中一条边",JOptionPane.INFORMATION_MESSAGE);
     a=Integer.parseInt(bian1);
    String bian2=JOptionPane.showInputDialog(null,"Enter a number","输入其中一条边",JOptionPane.INFORMATION_MESSAGE);
     b=Integer.parseInt(bian2);
    String bian3=JOptionPane.showInputDialog(null,"Enter a number","输入其中一条边",JOptionPane.INFORMATION_MESSAGE);
     c=Integer.parseInt(bian3);
    boolean roemin=(a+b>c||a+c>b||b+c>a);
    JOptionPane.showMessageDialog(null,"Can edges"+"  "+a+","+b+"  "+"and" +"  "+c+"  "+"from a triagle?"+"  "+roemin,"判断是不是三角    形",JOptionPane.INFORMATION_MESSAGE);
   
    JOptionPane.showMessageDialog(null,1/2*(Math.sqrt((1/2*(a+b+c))*((1/2*(a+b+c))-a)*((1/2*(a+b+c))-b)*((1/2*(a+b+c))-c))),"该三角形的面积是:",JOptionPane.INFORMATION_MESSAGE);
   }
}
     
    
    我想计算面积但是计算不出来啊.

解决方案 »

  1.   

    海伦公式是
    Math.sqrt(p * ((p - a) * (p - b) * (p - c)));
    不用再除2了
    且运算期间不要用1/2这种形式 换用0.5
      

  2.   

    用海伧公式
    JOptionPane.showMessageDialog(null,1/2*(Math.sqrt((1/2*(a+b+c))*((1/2*(a+b+c))-a)*((1/2*(a+b+c))-b)*((1/2*(a+b+c))-c)))
    楼上已经说明了
      

  3.   

    你这句是不是应该这样改?
    boolean roemin=(a+b>c&&a+c>b&&b+c>a); 
      

  4.   

    原来我少写了一句啊。
     if(roemin==true)