Rule of the triangle

  • 4
  • Locked
Can any three line segments be the sides of a triangle? You probably already guessed (or remembered from high-school geometry) that you can only have a triangle if the sum of the lengths of any two sides is greater than the length of the third side. Well, now we're going to write code to check whether 3 line segments are suitable for forming a triangle.
You can't complete this task, because you're not signed in.
Comments (15)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Erextor Level 7, Moscow, Russian Federation
19 October 2020, 05:58
what is wrong with my code, i dont understand: package com.codegym.task.task04.task0415; /*
Joe M Level 9, East Coast, United States
25 September 2020, 20:36
I use scanner :(
Switch/Cypher Level 25, Bexleyheath, United Kingdom
7 September 2020, 09:13
How are you all getting the keyboard input data to be stored in separate ints? Am I missing something? BufferedReader only returns a three digit number. Also for this and the exercise before you need parseInt, which I looked up, but hasn't been taught.
Myko Level 6, Dresden, Germany
24 November 2020, 09:42
Hi! To get the keyboard input data to be stored in separate ints I use this: InputStream inputStream = System.in; Reader InputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(InputStreamReader); and of course I need parseInt to let the programm know, that I`m now working with numbers. It looks like this: String firstNumber = bufferedReader.readLine(); int Num1 = Integer.parseInt(firstNumber);
Clark Willms Level 9, Omaha, United States
7 August 2020, 15:28
My code works but I'm not getting the last task correct. This is the 3rd project in this lesson where the output is correct but the project isn't completing. else{ System.out.println("The triangle is possible.");
Martzehh Level 9, Ottawa, Canada
31 May 2020, 16:31
Like the others have said, the question description is off.
Brandon Nicolle Level 5, Edmonton, Canada
17 August 2019, 23:00
Why am I getting a error that say else without if, how do I word this incorrectly?
Mikael Fridh Level 9, Bjärnum, Sweden
27 March 2019, 20:02
The description is off. "A triangle can exist only if the sum of any two of its sides is greater than the third side." Should've said ".. is greater than- or equal to the third side.".
Roman Level 41
28 March 2019, 07:06
Give a picture of a triangle in which the sum of any two sides is equal to the third. )
Mikael Fridh Level 9, Bjärnum, Sweden
28 March 2019, 19:23
Jokes aside. Still only says greater than. Not everyone knows their geometry. Because, if it can't exist, it shouldn't have been checked for either. (equals)
Janusz Level 11, Radomsko, Poland
5 December 2018, 09:20
using > = instead of just >
Suhinder lal Level 7, Khanpur, Pakistan
5 August 2018, 10:00
A triangle can exist only if the sum of any two of its sides is greater than the third side. You need to compare each side with the sum of the other two. If even one side is larger than the sum of the other two sides, then no such triangle exists. if (a>(b+c) || b>(a+c) || c>(b+a)) System.out.println("The triangle is not possible."); else System.out.println("The triangle is possible."); why its not working
Roman Level 41
6 August 2018, 11:05
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
Azhar Iqbal Level 18, Multan, Pakistan
3 September 2018, 19:22
bro use AND operator instead of OR...
jothilearner Level 7, Chennai, India
8 June 2019, 09:30
to check with >= condition also it will work fine