السؤال بسيط، يقولك سوي برنامج يدخل 3 حدود للمثلث ويكتشف إذا كان الحل صحيح أو لأ ؟
كيف تعرف إذا كان الحل صحيح أو لأ ؟ إذا كان مجموع حدين من الثلاثة حدود أكبر من الحد الثالث،
السورس كود:
كود PHP:
import java.util.*;
public class edgesoftriangle {
public static void main(string[] args) {
int n1,n2,n3;
scanner input=new scanner(system.in);
system.out.println("enter 1st edge of the triangle: ");
n1 = input.nextint();
system.out.println("enter 2nd edge of the triangle: ");
n2 = input.nextint();
system.out.println("enter 3rd edge of the triangle: ");
n3 = input.nextint();
if ((n1+n2>n3) && (n2+n3 >n1) && (n3+n1 > n2))
system.out.println("can edge "+n1+", "+n2+", and "+n3+" form a triangle? True");
else
system.out.println("can edge "+n1+", "+n2+", and "+n3+" form a triangle? False");
}
}
بالتوفيق