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.
Rule of the triangle
- 4
Locked
Comments (17)
- Popular
- New
- Old
You must be signed in to leave a comment
Erextor
19 October 2020, 05:58
what is wrong with my code, i dont understand:
package com.codegym.task.task04.task0415;
/*
0
Joe M
25 September 2020, 20:36
I use scanner :(
0
Switch/Cypher
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.
0
Myko
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);
0
Clark Willms
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.");
+1
Okan Barış Özcan
16 November 2021, 19:22
You should think equal condition also.
+2
Martzehh
31 May 2020, 16:31
Like the others have said, the question description is off.
+2
Brandon Nicolle
17 August 2019, 23:00
Why am I getting a error that say else without if, how do I word this incorrectly?
0
Mikael Fridh
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.".
+1
Roman
28 March 2019, 07:06
Give a picture of a triangle in which the sum of any two sides is equal to the third. )
+1
Mikael Fridh
28 March 2019, 19:23

+6
Janusz
5 December 2018, 09:20
using > = instead of just >
0
Suhinder lal
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
+3
Roman
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.
0
Azhar Iqbal
3 September 2018, 19:22
bro use AND operator instead of OR...
+15
jothilearner
8 June 2019, 09:30
to check with >= condition also it will work fine
+2
Folpo
3 November 2021, 09:39
Azhar, if i use AND instead of OR, does it means that all 3 condition must be TRUE? but a triangle cannot have all 3 conditions TRUE at the same time.. only one condition at time. so why does it work?
0