why I need to assign length1,2,3=0 at the beginning?

تعرفه تبلیغات در سایت
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس

آرشیو مطالب

جستجوگر

یافته ها در جستجو

    امکانات وب

    برچسب ها

    Vote count: 0

    /*If you have three positive integers, you can determine whether or not those three values could represent the three sides of a triangle. If they do happen to represent a triangle, you can even determine what type of triangle it is (equilateral, isosceles, or scalene).

    Write a program, called TriangleTypes.java, that will determine if the given lengths of three sides of a triangle (either given by the user or generated randomly) represent a valid triangle and if so what type of triangle it is.

    If three given lengths are to represent a valid triangle, the sum of the lengths of any two sides must be greater than the third side.*/ import java.util.Scanner;

    public class NewB {

    public static void main(String[] args) {
        System.out.println("Welcome to TriangleTypes Program");
        Scanner input = new Scanner(System.in);
        System.out.println("1 – Enter the lengths of the three sides myself"
                + "   2 – Let the computer generate three random lengths");
        int number = input.nextInt();
        int length1 = 0;
        int length2 = 0;
        int length3 = 0;
        switch (number) {
    
            case 1:
                System.out.println(" Please enter the lengths of the three sides"
                        + " of your triangle" + "(positive integers only: )");
    
                length1 = input.nextInt();
                 length2 = input.nextInt();
               length3 = input.nextInt();
                break;
    
            case 2:
                length1 = (int) (Math.random() * 15 + 1);
                length2 = (int) (Math.random() * 15 + 1);
                length3 = (int) (Math.random() * 15 + 1);
                System.out.println("The computer generated these three sides:" + length1
                        + " " + length2 + " " + length3);
        }
        if (length1 + length2 > length3 && length1 + length3 > length2 && length2 + length3 > length1) {
    
            if (length1 == length2 && length2 == length3) {
                System.out.println("This is an euqilateral triangle");
            } else if (length1 == length2 || length1 == length3 || length2 == length3) {
                System.out.println("This is an isosceles triangle");
            } else {
                System.out.println("This is a scalene triangle");
            }
        } else {
            System.out.println("This is not a valid triangle");
        }
    }
    

    }

    asked 1 min ago
    cong ma

    نویسنده : استخدام کار بازدید : 7 تاريخ : دوشنبه 27 شهريور 1396 ساعت: 1:53
    برچسب‌ها :

    خبرنامه

    عضویت

    نام کاربري :
    رمز عبور :