Question

Java problem How to write a method that does not take any paramter which returns the...

Java problem

How to write a method that does not take any paramter which returns the circumference of the triangle formed by 3 points and returns -1 if it is unvalid?

thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


import java.util.Scanner;

public class TriangleCircum {
   public static void main(String[] args) {
       System.out.println("Circumstance: " + getCircumstance());
   }
   public static double getCircumstance() {
       Scanner sc = new Scanner(System.in);

//reading values from user
       System.out.println("Enter 3 sides of triagnle: ");
       double side1 = sc.nextDouble();
       double side2 = sc.nextDouble();
       double side3 = sc.nextDouble();
       sc.close();

// checking for valid sides
       if ((side1 + side2) > side3)
           return -1;

//returning circumstance of triangle
       return side1 + side2 + side3;
   }
}

Add a comment
Know the answer?
Add Answer to:
Java problem How to write a method that does not take any paramter which returns the...
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