CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Jaisingh
Level 14
Hyderabad
  • 15.09.2018
  • 1379views
  • 5comments

what is a trianle with the specified side, i did not get that, please any body explain me that with the example

Question about the task Rule of the triangle
Java Syntax,  Level 4,  Lesson 4
Under discussion


Use the keyboard to enter three numbers a, b, and c (the lengths of the sides of the proposed triangle).
Determine whether a triangle with these sides can exist.
Display the result as follows:
"The triangle is possible." - if a triangle with these sides could exist.
"The triangle is not possible." - if a triangle with these sides cannot exist.

Hint:
A triangle can exist only if the sum of 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 or equal to the sum of the other two sides, then no such triangle exists.

Requirements:
  • The program should read three numbers from the keyboard.
  • The program should display text on the screen according to the task conditions.
  • If a triangle with the specified sides could exist, you need to display: "The triangle is possible."
  • If a triangle with the specified sides cannot exist, you need to display: "The triangle is not possible."
package com.codegym.task.task04.task0415; /* Rule of the triangle */ import java.io.*; public class Solution { public static void main(String[] args) throws Exception { //write your code here // ask to enter input from input consol BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String num1 = bf.readLine(); String num2 = bf.readLine(); String num3 = bf.readLine(); int numA = Integer.parseInt(num1); int numB = Integer.parseInt(num2); int numC = Integer.parseInt(num3); checkTriagle (numA, numB, numC); } public static void checkTriagle (int a, int b, int c) { if (a + b > c) { if (b + c > a) { if (c + a > b) System.out.println("The triangle is possible."); else System.out.println("The triagle is not possible."); } else System.out.println("The triangle is not possible."); } else System.out.println("The triangle is not possible."); } }
0
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Love Patel
Level 5 , San Leandro, United States
5 December 2018, 03:16
there is a typo in your top most else statement
0
Brice
Level 8 , Douala, Cameroun
26 November 2018, 10:10
Don't see why, it should run. thsi is the solution: if(a + b > c) if(a + c > b) if(b + c > a) System.out.println("The triangle is possible."); else System.out.println("The triangle is not possible."); else System.out.println("The triangle is not possible."); else System.out.println("The triangle is not possible.");
0
Anonymous #188267
Level 4 , Karachi, Pakistan
22 September 2018, 03:56
A triangle can exist only if the sum of any two of its sides is greater than the third side. Means a + b > c or b + c > a or c + a > b 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. You are not separating this conditions instead you are making conditions which are interlinked together if one condition is true then go to next condition and if that condition is true than execute that condition. Simply, there are three three conditions (a + b > c or b + c > a or c + a > b)
0
Ravi Kumar
Level 5 , Hyderabad, India
19 November 2018, 14:48
It should "and" not "OR" in the if condition
0
Khurram
Level 16 , Lahore, Pakistan
15 September 2018, 05:24
there is a typo in the inner most if else block
+1
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.