# Isosceles Triangle Code Errors

Page 1 of 1

## 5 Replies - 2611 Views - Last Post: 29 November 2011 - 05:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=257715&amp;s=7f6b72f7039195da53062c1ca5f645f3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Th3T3chGuy

Reputation: -3
• Posts: 73
• Joined: 16-October 11

# Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:01 PM

I have to write a method that expects three parameters representing the three sides of a triangle. It returns true if the lengths of the 3 sides result in a isosceles triangle and returns false otherwise.

Here is what I got so far:

```import java.util.Scanner;

public class Problem6{
public static void main (String [] args){

int sidea, sideb, sidec;

System.out.println("Enter the length of the first side:");

System.out.println("Enter the length of the second side:");

System.out.println("Enter the length of the third side:");

int isoscelesTriangle = isIsosceles(sidea, sideb, sidec);

System.out.println("The area of the square is: " + isoscelesTriangle + " cm^2.");
}

public static int isIsosceles(int sidea, int sideb, int sidec){

int isoscelesTriangle;
if (sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec){
System.out.println("True");

else{
System.out.println("False");
return isoscelesTriangle;
}
}
}
}
```

These are the erros I get when I compile:

```---------- Capture Output ----------
"C:\Program Files\Java\jdk1.7.0\bin\javac.exe" Problem6.java
Problem6.java:26: error: illegal start of expression
if (sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec){
^
Problem6.java:26: error: ';' expected
if (sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec){
^
Problem6.java:29: error: 'else' without 'if'
else{
^
3 errors
Terminated with exit code 1
```

Is This A Good Question/Topic? 0

## Replies To: Isosceles Triangle Code Errors

### #2 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:07 PM

This line:

if (sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec)

simplified says:

if ( this ) && !(that)

which is not a correct if statement. It should read:

if ( (this) && !(that) )

Fix that and then move to the next error.

### #3 Swillis57

Reputation: 9
• Posts: 34
• Joined: 14-January 11

## Re: Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:11 PM

You forgot some parenthesis in the if-statements. Add one '(' before the "sidea" variable in each statement, then add one ')' at the end of the conditionals.

As for the "else" error, there's no curly-brace closing the previous if-block, add one "}" before the else.

### #4 smohd

• Critical Section

Reputation: 1824
• Posts: 4,627
• Joined: 14-March 10

## Re: Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:16 PM

Also you are returning a value that has not been initialized: return isoscelesTriangle;
But why you return int? it looks like it should return boolean

### #5 Th3T3chGuy

Reputation: -3
• Posts: 73
• Joined: 16-October 11

## Re: Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:18 PM

Ok my revised code looks like this:

```import java.util.Scanner;

public class Problem6{
public static void main (String [] args){

int sidea, sideb, sidec;

System.out.println("Enter the length of the first side:");

System.out.println("Enter the length of the second side:");

System.out.println("Enter the length of the third side:");

int isoscelesTriangle = isIsosceles(sidea, sideb, sidec);

System.out.println("The area of the square is: " + isoscelesTriangle + " cm^2.");
}

public static int isIsosceles(int sidea, int sideb, int sidec){

int isoscelesTriangle;
if ((sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec)){
System.out.println("True");

}else{
System.out.println("False");
return isoscelesTriangle;
}

}
}
```

But now I'm getting a new error:

```---------- Capture Output ----------
"C:\Program Files\Java\jdk1.7.0\bin\javac.exe" Problem6.java
Problem6.java:26: error: incomparable types: boolean and int
if ((sidea == sideb || sideb == sidec || sidea == sidec) && !(sidea == sideb == sidec)){
^
1 error
Terminated with exit code 1
```

### #6 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Isosceles Triangle Code Errors

Posted 29 November 2011 - 05:23 PM

Recheck your if statement. Hint: rephrase a == b == c.