# Isosceles Triangle Code Errors

Page 1 of 1

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

### #1 Th3T3chGuy

• D.I.C Head

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){
Scanner reader = new Scanner(System.in);

int sidea, sideb, sidec;

System.out.println("Enter the length of the first side:");
sidea = reader.nextInt();

System.out.println("Enter the length of the second side:");
sideb = reader.nextInt();

System.out.println("Enter the length of the third side:");
sidec = reader.nextInt();

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: 2215
• Posts: 5,240
• 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.
Was This Post Helpful? 0

### #3 Swillis57

• New D.I.C Head

Reputation: 8
• Posts: 32
• 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.
Was This Post Helpful? 0

### #4 smohd

• Critical Section

Reputation: 1820
• 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
Was This Post Helpful? 0

### #5 Th3T3chGuy

• D.I.C Head

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){
Scanner reader = new Scanner(System.in);

int sidea, sideb, sidec;

System.out.println("Enter the length of the first side:");
sidea = reader.nextInt();

System.out.println("Enter the length of the second side:");
sideb = reader.nextInt();

System.out.println("Enter the length of the third side:");
sidec = reader.nextInt();

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
```

Was This Post Helpful? 0

### #6 GregBrannon

• D.I.C Lover

Reputation: 2215
• Posts: 5,240
• 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.
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }