If statements not working correctly in program to determine triangle typeCan I have someone verify my collections for the SCJP ExamDecoding colored image using ZXing library in Javahow to perform a functional test on a triangleWhat should I use for the while loop?why spill failure happens for Custom Data Type in HadoopIf Elif Else Chain To Classify Triangle (Python)Triangle Side & Angle Classification GeneratorA condition in a C program doesn't give the desired resultKeep getting this error message for my RockPaperScissor Program. How do I fix this error?Java Methods - Calling and Defining
Blocking people from taking pictures of me with smartphone
Is it possible to script what applications should open certain file extensions?
SQL Minimum Row count
Short story about a teenager who has his brain replaced with a microchip (Psychological Horror)
Word or idiom defining something barely functional
How do we avoid CI-driven development...?
Best gun to modify into a monsterhunter weapon?
sed delete all the words before a match
Ex-contractor published company source code and secrets online
Is it really ~648.69 km/s delta-v to "land" on the surface of the Sun?
Double blind peer review when paper cites author's GitHub repo for code
Dropdowns & Chevrons for Right to Left languages
Are there any financial disadvantages to living significantly "below your means"?
Plausibility of Ice Eaters in the Arctic
Generator for parity?
Is multiplication of real numbers uniquely defined as being distributive over addition?
Team goes to lunch frequently, I do intermittent fasting but still want to socialize
How to identify the wires on the dimmer to convert it to Conventional on/off switch
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
Can an SPI slave start a transmission in full-duplex mode?
Can a PC attack themselves with an unarmed strike?
Dereferencing a pointer in a for loop initializer creates a seg fault
Non-OR journals which regularly publish OR research
What is the idiomatic way of saying “he is ticklish under armpits”?
If statements not working correctly in program to determine triangle type
Can I have someone verify my collections for the SCJP ExamDecoding colored image using ZXing library in Javahow to perform a functional test on a triangleWhat should I use for the while loop?why spill failure happens for Custom Data Type in HadoopIf Elif Else Chain To Classify Triangle (Python)Triangle Side & Angle Classification GeneratorA condition in a C program doesn't give the desired resultKeep getting this error message for my RockPaperScissor Program. How do I fix this error?Java Methods - Calling and Defining
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an assignment to write a program that uses the method triangleType that i must write to take three int inputs from the user and output the triangle type. In the method, I first need to sort the integers in ascending order so that the comparisons I am required to use will work correctly. I know I did the sorting part in the code correctly, because I tested it before I even started trying to determine the triangle type. I am required to use these comparisons to find the triangle type: "if A + B <= C, then the sides do not represent a valid triangle. if A = C (all the sides must be the same length) then the triangle is EQUILATERAL. if A = B or B = C, then the triangle is ISOSCELES; otherwise the triangle is SCALENE"
For some reasons my if statements at the end of the triangleType method are not working correctly and I get all sorts of output, including "Invalid Triangle" plus other outputs no matter the integers that I enter.
package trianglemethod;
import javax.swing.JOptionPane;
public class TriangleMethod
public static void main(String[] args)
String wordaA, wordbB, wordcC, answer;
do
System.out.println("Please enter all 3 side lengths of the triangle in any order.");
wordaA = JOptionPane.showInputDialog("Enter side 1:");
wordbB = JOptionPane.showInputDialog("Enter side 2:");
wordcC = JOptionPane.showInputDialog("Enter side 3:");
int aA = Integer.parseInt(wordaA);
int bB = Integer.parseInt(wordbB);
int cC = Integer.parseInt(wordcC);
triangleType(aA,bB,cC);
System.out.println("Would you like to enter another triangle?");
answer = JOptionPane.showInputDialog("Would you like to enter another triangle?");
while (answer.equalsIgnoreCase("yes"));
static void triangleType(int aA, int bB, int cC) b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
java if-statement
add a comment |
I have an assignment to write a program that uses the method triangleType that i must write to take three int inputs from the user and output the triangle type. In the method, I first need to sort the integers in ascending order so that the comparisons I am required to use will work correctly. I know I did the sorting part in the code correctly, because I tested it before I even started trying to determine the triangle type. I am required to use these comparisons to find the triangle type: "if A + B <= C, then the sides do not represent a valid triangle. if A = C (all the sides must be the same length) then the triangle is EQUILATERAL. if A = B or B = C, then the triangle is ISOSCELES; otherwise the triangle is SCALENE"
For some reasons my if statements at the end of the triangleType method are not working correctly and I get all sorts of output, including "Invalid Triangle" plus other outputs no matter the integers that I enter.
package trianglemethod;
import javax.swing.JOptionPane;
public class TriangleMethod
public static void main(String[] args)
String wordaA, wordbB, wordcC, answer;
do
System.out.println("Please enter all 3 side lengths of the triangle in any order.");
wordaA = JOptionPane.showInputDialog("Enter side 1:");
wordbB = JOptionPane.showInputDialog("Enter side 2:");
wordcC = JOptionPane.showInputDialog("Enter side 3:");
int aA = Integer.parseInt(wordaA);
int bB = Integer.parseInt(wordbB);
int cC = Integer.parseInt(wordcC);
triangleType(aA,bB,cC);
System.out.println("Would you like to enter another triangle?");
answer = JOptionPane.showInputDialog("Would you like to enter another triangle?");
while (answer.equalsIgnoreCase("yes"));
static void triangleType(int aA, int bB, int cC) b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
java if-statement
I think you will find your life easier if you make several methods, such asisValidTriangle(int a, int b, int c)
andisIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complexif/else if/else
statements. A good general principle is that a method should do one thing well.
– KevinO
Mar 27 at 6:02
add a comment |
I have an assignment to write a program that uses the method triangleType that i must write to take three int inputs from the user and output the triangle type. In the method, I first need to sort the integers in ascending order so that the comparisons I am required to use will work correctly. I know I did the sorting part in the code correctly, because I tested it before I even started trying to determine the triangle type. I am required to use these comparisons to find the triangle type: "if A + B <= C, then the sides do not represent a valid triangle. if A = C (all the sides must be the same length) then the triangle is EQUILATERAL. if A = B or B = C, then the triangle is ISOSCELES; otherwise the triangle is SCALENE"
For some reasons my if statements at the end of the triangleType method are not working correctly and I get all sorts of output, including "Invalid Triangle" plus other outputs no matter the integers that I enter.
package trianglemethod;
import javax.swing.JOptionPane;
public class TriangleMethod
public static void main(String[] args)
String wordaA, wordbB, wordcC, answer;
do
System.out.println("Please enter all 3 side lengths of the triangle in any order.");
wordaA = JOptionPane.showInputDialog("Enter side 1:");
wordbB = JOptionPane.showInputDialog("Enter side 2:");
wordcC = JOptionPane.showInputDialog("Enter side 3:");
int aA = Integer.parseInt(wordaA);
int bB = Integer.parseInt(wordbB);
int cC = Integer.parseInt(wordcC);
triangleType(aA,bB,cC);
System.out.println("Would you like to enter another triangle?");
answer = JOptionPane.showInputDialog("Would you like to enter another triangle?");
while (answer.equalsIgnoreCase("yes"));
static void triangleType(int aA, int bB, int cC) b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
java if-statement
I have an assignment to write a program that uses the method triangleType that i must write to take three int inputs from the user and output the triangle type. In the method, I first need to sort the integers in ascending order so that the comparisons I am required to use will work correctly. I know I did the sorting part in the code correctly, because I tested it before I even started trying to determine the triangle type. I am required to use these comparisons to find the triangle type: "if A + B <= C, then the sides do not represent a valid triangle. if A = C (all the sides must be the same length) then the triangle is EQUILATERAL. if A = B or B = C, then the triangle is ISOSCELES; otherwise the triangle is SCALENE"
For some reasons my if statements at the end of the triangleType method are not working correctly and I get all sorts of output, including "Invalid Triangle" plus other outputs no matter the integers that I enter.
package trianglemethod;
import javax.swing.JOptionPane;
public class TriangleMethod
public static void main(String[] args)
String wordaA, wordbB, wordcC, answer;
do
System.out.println("Please enter all 3 side lengths of the triangle in any order.");
wordaA = JOptionPane.showInputDialog("Enter side 1:");
wordbB = JOptionPane.showInputDialog("Enter side 2:");
wordcC = JOptionPane.showInputDialog("Enter side 3:");
int aA = Integer.parseInt(wordaA);
int bB = Integer.parseInt(wordbB);
int cC = Integer.parseInt(wordcC);
triangleType(aA,bB,cC);
System.out.println("Would you like to enter another triangle?");
answer = JOptionPane.showInputDialog("Would you like to enter another triangle?");
while (answer.equalsIgnoreCase("yes"));
static void triangleType(int aA, int bB, int cC) b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
java if-statement
java if-statement
edited Mar 27 at 9:35
Mureinik
197k24 gold badges161 silver badges219 bronze badges
197k24 gold badges161 silver badges219 bronze badges
asked Mar 27 at 5:58
SterlingHSterlingH
133 bronze badges
133 bronze badges
I think you will find your life easier if you make several methods, such asisValidTriangle(int a, int b, int c)
andisIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complexif/else if/else
statements. A good general principle is that a method should do one thing well.
– KevinO
Mar 27 at 6:02
add a comment |
I think you will find your life easier if you make several methods, such asisValidTriangle(int a, int b, int c)
andisIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complexif/else if/else
statements. A good general principle is that a method should do one thing well.
– KevinO
Mar 27 at 6:02
I think you will find your life easier if you make several methods, such as
isValidTriangle(int a, int b, int c)
and isIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complex if/else if/else
statements. A good general principle is that a method should do one thing well.– KevinO
Mar 27 at 6:02
I think you will find your life easier if you make several methods, such as
isValidTriangle(int a, int b, int c)
and isIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complex if/else if/else
statements. A good general principle is that a method should do one thing well.– KevinO
Mar 27 at 6:02
add a comment |
3 Answers
3
active
oldest
votes
You have three different if
statements there that are evaluated separately. Instead, from the description of the problem, it sounds like you need a single if
statement with multiple condition branches (i.e., else if
clauses):
if (a+b<=c)
JOptionPane.showMessageDialog(null,"Invalid Triangle");
else if (a==c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if (a==b || b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
add a comment |
I'm confused, why can't you just do
if (a == b && b == c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else if (a != b && a != c && b != c)
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
else
JOptionPane.showMessageDialog(null,"Invalid Triangle");
add a comment |
There's actually 2 issues.
Let's say a=5, b=5, and c=5. The way your code is working right now it checks:if (a==c)
which is true, so it prints "Triangle is Equilateral". Then it checks:if (a==b || b==c)
which is also true, so it prints "Triangle is Isosceles".
In order to prevent it from checking the next if statement once it finds the result you are looking for, all following if statements have to be "else if" statements. The final "else" code will run if all the else if statements above it are false. In your case, it will run as long as your third if statement is false.
Also as Andronicus pointed out, the variables a, b, and c will remain 0 if any side is equal to another as your code only checks for inequalities
Here is working code for the sorting part:if(aA>=bB && aA>=cC)
a = aA;
if(bB >= cC)
b = bB;
c = cC;
else
b = cC;
c = bB;
else if (bB >= aA && bB >= cC)
a = bB;
if(aA >= cC)
b = aA;
c = cC;
else
b = cC;
a = aA;
else
a = cC;
if(cC >= aA)
b = cC;
c = aA;
else
b = aA;
c = cC;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370676%2fif-statements-not-working-correctly-in-program-to-determine-triangle-type%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have three different if
statements there that are evaluated separately. Instead, from the description of the problem, it sounds like you need a single if
statement with multiple condition branches (i.e., else if
clauses):
if (a+b<=c)
JOptionPane.showMessageDialog(null,"Invalid Triangle");
else if (a==c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if (a==b || b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
add a comment |
You have three different if
statements there that are evaluated separately. Instead, from the description of the problem, it sounds like you need a single if
statement with multiple condition branches (i.e., else if
clauses):
if (a+b<=c)
JOptionPane.showMessageDialog(null,"Invalid Triangle");
else if (a==c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if (a==b || b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
add a comment |
You have three different if
statements there that are evaluated separately. Instead, from the description of the problem, it sounds like you need a single if
statement with multiple condition branches (i.e., else if
clauses):
if (a+b<=c)
JOptionPane.showMessageDialog(null,"Invalid Triangle");
else if (a==c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if (a==b || b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
You have three different if
statements there that are evaluated separately. Instead, from the description of the problem, it sounds like you need a single if
statement with multiple condition branches (i.e., else if
clauses):
if (a+b<=c)
JOptionPane.showMessageDialog(null,"Invalid Triangle");
else if (a==c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if (a==b || b==c)
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
answered Mar 27 at 6:04
MureinikMureinik
197k24 gold badges161 silver badges219 bronze badges
197k24 gold badges161 silver badges219 bronze badges
add a comment |
add a comment |
I'm confused, why can't you just do
if (a == b && b == c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else if (a != b && a != c && b != c)
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
else
JOptionPane.showMessageDialog(null,"Invalid Triangle");
add a comment |
I'm confused, why can't you just do
if (a == b && b == c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else if (a != b && a != c && b != c)
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
else
JOptionPane.showMessageDialog(null,"Invalid Triangle");
add a comment |
I'm confused, why can't you just do
if (a == b && b == c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else if (a != b && a != c && b != c)
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
else
JOptionPane.showMessageDialog(null,"Invalid Triangle");
I'm confused, why can't you just do
if (a == b && b == c)
JOptionPane.showMessageDialog(null,"Triangle is Equilateral");
else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
JOptionPane.showMessageDialog(null, "Triangle is Isosceles");
else if (a != b && a != c && b != c)
JOptionPane.showMessageDialog(null,"Triangle is Scalene");
else
JOptionPane.showMessageDialog(null,"Invalid Triangle");
answered Mar 27 at 6:07
chrischris
514 bronze badges
514 bronze badges
add a comment |
add a comment |
There's actually 2 issues.
Let's say a=5, b=5, and c=5. The way your code is working right now it checks:if (a==c)
which is true, so it prints "Triangle is Equilateral". Then it checks:if (a==b || b==c)
which is also true, so it prints "Triangle is Isosceles".
In order to prevent it from checking the next if statement once it finds the result you are looking for, all following if statements have to be "else if" statements. The final "else" code will run if all the else if statements above it are false. In your case, it will run as long as your third if statement is false.
Also as Andronicus pointed out, the variables a, b, and c will remain 0 if any side is equal to another as your code only checks for inequalities
Here is working code for the sorting part:if(aA>=bB && aA>=cC)
a = aA;
if(bB >= cC)
b = bB;
c = cC;
else
b = cC;
c = bB;
else if (bB >= aA && bB >= cC)
a = bB;
if(aA >= cC)
b = aA;
c = cC;
else
b = cC;
a = aA;
else
a = cC;
if(cC >= aA)
b = cC;
c = aA;
else
b = aA;
c = cC;
add a comment |
There's actually 2 issues.
Let's say a=5, b=5, and c=5. The way your code is working right now it checks:if (a==c)
which is true, so it prints "Triangle is Equilateral". Then it checks:if (a==b || b==c)
which is also true, so it prints "Triangle is Isosceles".
In order to prevent it from checking the next if statement once it finds the result you are looking for, all following if statements have to be "else if" statements. The final "else" code will run if all the else if statements above it are false. In your case, it will run as long as your third if statement is false.
Also as Andronicus pointed out, the variables a, b, and c will remain 0 if any side is equal to another as your code only checks for inequalities
Here is working code for the sorting part:if(aA>=bB && aA>=cC)
a = aA;
if(bB >= cC)
b = bB;
c = cC;
else
b = cC;
c = bB;
else if (bB >= aA && bB >= cC)
a = bB;
if(aA >= cC)
b = aA;
c = cC;
else
b = cC;
a = aA;
else
a = cC;
if(cC >= aA)
b = cC;
c = aA;
else
b = aA;
c = cC;
add a comment |
There's actually 2 issues.
Let's say a=5, b=5, and c=5. The way your code is working right now it checks:if (a==c)
which is true, so it prints "Triangle is Equilateral". Then it checks:if (a==b || b==c)
which is also true, so it prints "Triangle is Isosceles".
In order to prevent it from checking the next if statement once it finds the result you are looking for, all following if statements have to be "else if" statements. The final "else" code will run if all the else if statements above it are false. In your case, it will run as long as your third if statement is false.
Also as Andronicus pointed out, the variables a, b, and c will remain 0 if any side is equal to another as your code only checks for inequalities
Here is working code for the sorting part:if(aA>=bB && aA>=cC)
a = aA;
if(bB >= cC)
b = bB;
c = cC;
else
b = cC;
c = bB;
else if (bB >= aA && bB >= cC)
a = bB;
if(aA >= cC)
b = aA;
c = cC;
else
b = cC;
a = aA;
else
a = cC;
if(cC >= aA)
b = cC;
c = aA;
else
b = aA;
c = cC;
There's actually 2 issues.
Let's say a=5, b=5, and c=5. The way your code is working right now it checks:if (a==c)
which is true, so it prints "Triangle is Equilateral". Then it checks:if (a==b || b==c)
which is also true, so it prints "Triangle is Isosceles".
In order to prevent it from checking the next if statement once it finds the result you are looking for, all following if statements have to be "else if" statements. The final "else" code will run if all the else if statements above it are false. In your case, it will run as long as your third if statement is false.
Also as Andronicus pointed out, the variables a, b, and c will remain 0 if any side is equal to another as your code only checks for inequalities
Here is working code for the sorting part:if(aA>=bB && aA>=cC)
a = aA;
if(bB >= cC)
b = bB;
c = cC;
else
b = cC;
c = bB;
else if (bB >= aA && bB >= cC)
a = bB;
if(aA >= cC)
b = aA;
c = cC;
else
b = cC;
a = aA;
else
a = cC;
if(cC >= aA)
b = cC;
c = aA;
else
b = aA;
c = cC;
edited Mar 27 at 6:52
answered Mar 27 at 6:05
Anthony YershovAnthony Yershov
227 bronze badges
227 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370676%2fif-statements-not-working-correctly-in-program-to-determine-triangle-type%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think you will find your life easier if you make several methods, such as
isValidTriangle(int a, int b, int c)
andisIsosceles(a, b, c)
and put the specific logic in separate methods (also easier to test) rather than trying to deal with complexif/else if/else
statements. A good general principle is that a method should do one thing well.– KevinO
Mar 27 at 6:02