Question

For JAVA- Write an application that reads three nonzero values entered by the user and determines...

For JAVA- Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class ValidateTriangle {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Please enter the sides of the triangle, separate by a space.");
        int s1 = in.nextInt();    // read first length
        int s2 = in.nextInt();    // read second length
        int s3 = in.nextInt();    // read third length

        if(s1+s2 > s3 && s2+s3 > s1 && s1+s3 > s2) {   // if triangle is valid
            System.out.println("Yes, this is a valid triangle.");
        } else {    // if triangle is not valid
            System.out.println("This is not a valid triangle.");   // report that to user
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
For JAVA- Write an application that reads three nonzero values entered by the user and determines...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT