//Judge whether 3 side lengths can be used to form a triangle
import javax.swing.*;

public class ISTriangle ...{
public static void main(String args[])

...{
double l1,l2,l3;
String L1,L2,L3;
boolean guard;
L1=JOptionPane.showInputDialog("Enter the first side length:");
L2=JOptionPane.showInputDialog("Enter the second side length:");
L3=JOptionPane.showInputDialog("Enter the third side length:");
l1=Double.parseDouble(L1);
l2=Double.parseDouble(L2);
l3=Double.parseDouble(L3);
guard=(l1+l2>l3&&l1+l3>l2&&l2+l3>l1);
if (guard)
JOptionPane.showMessageDialog(null, "A triangle can be formed by" +
" the three lengths","Triangle Judgement",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "A triangle can not be formed by" +
" the three lengths.","Triangle Judgement",JOptionPane.ERROR_MESSAGE);
}

}

发表于 @ 2008年04月07日 17:27:00|评论(loading...)|编辑