Computer Science, asked by tanishapaul1340, 1 month ago

Help me with this program ( class 9)
if you spam i will report your account as well as your answer❌​

Attachments:

tanishapaul1340: yes java
udayagrawal49: Okay wait... I will add ans in 10 min.
tanishapaul1340: ok thank you
tanishapaul1340: can you please give me the output as well?
Anonymous: 9561089359
1234
yup fast
udayagrawal49: I will to give output as well... you have to wait for about 15 min.
tanishapaul1340: okk please give .. i will wait
udayagrawal49: area of equilateral triangle is root(3)/4 side^2... in image, it is written root(3)/2 side^2
tanishapaul1340: please do according to image given
udayagrawal49: okay

Answers

Answered by udayagrawal49
3

Answer: The required java program is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    System.out.print("Enter first side of triangle : ");

    int a = scan.nextInt();

    System.out.print("Enter second side of triangle : ");

    int b = scan.nextInt();

    System.out.print("Enter third side of triangle : ");

    int c = scan.nextInt();

    scan.close();

    double area = 0.0;

    if((a+b)>c) {

        if((b+c)>a) {

            if((c+a)>b) {

                if(a==b && b==c) {

                    area = (Math.sqrt(3)/2)*(Math.pow(a,2));

                    System.out.print("It is an equilateral triangle and its area is "+area+" sq. units.");

                }

                else if((Math.pow(a,2)+Math.pow(b,2))==Math.pow(c,2)) {

                    area = 0.5*a*b;

                    System.out.println("It is a right-angled triangle and its area is "+area+" sq. units.");

                }

                else if((Math.pow(b,2)+Math.pow(c,2))==Math.pow(a,2)) {

                    area = 0.5*b*c;

                    System.out.println("It is a right-angled triangle and its area is "+area+" sq. units.");

                }

                else if((Math.pow(c,2)+Math.pow(a,2))==Math.pow(b,2)) {

                    area = 0.5*c*a;

                    System.out.println("It is a right-angled triangle and its area is "+area+" sq. units.");

                }

                else {

                    double s = (double)(a+b+c)/2;

                    area = Math.sqrt(s*(s-a)*(s-b)*(s-c));

                    System.out.println("The area of triangle is "+area+" sq. units.");

                }

            }

            else {

                System.out.println("A triangle cannot be formed.");

            }

        }

        else {

            System.out.println("A triangle cannot be formed.");

        }

    }

    else {

        System.out.println("A triangle cannot be formed.");

    }

   }

}

Input :-

Enter first side of triangle : 3

Enter second side of triangle : 6

Enter third side of triangle : 8

Output :-

The area of triangle is 7.644442425710328 sq. units.

Input :-

Enter first side of triangle : 3

Enter second side of triangle : 3

Enter third side of triangle : 3

Output :-

It is an equilateral triangle and its area is 7.794228634059947 sq. units.

Input :-

Enter first side of triangle : 3

Enter second side of triangle : 4

Enter third side of triangle : 5

Output :-

It is a right-angled triangle and its area is 6.0 sq. units.

Input :-

Enter first side of triangle : 1

Enter second side of triangle : 2

Enter third side of triangle : 3

Output :-

A triangle cannot be formed.

Note :-

The above program is stored in file named Main.java

Also, try-catch block can be used to avoid any type of error.


tanishapaul1340: Thank you so much
udayagrawal49: Welcome sis... if you want other Java programs, then feel free to ask sis
tanishapaul1340: ok bro thanks a lot
tanishapaul1340: i will ask you only from next time bro
Answered by rohitisnauty122
0

Answer:

please I am sorry please give ur number I tell u reasons lpease dear friend

Similar questions