# Thread: Why is the logic not correct?

1. Member Join Date
Jan 2015
Posts
48
Rep Power
0

## Why is the logic not correct?

Why is the logic not correct with the method public static boolean containsColor(String color, Circle [] ca)? It only returns me only false values.

Java Code:
```public class Circle {

private double radius;
private String color;

public Circle()
{
radius = 1;
color = "red";
}

public Circle(String color, double radius)
{
this.color = color;
this.radius = radius;
}

public String getColor()
{
return this.color;
}

public double getRadius()
{
return this.radius;
}

public static boolean containsColor(String color, Circle [] ca)
{

for (int i = 0; i < ca.length; i++)
{
if(ca[i].equals(color))
return true;
}
return false;

}
}

public class UseCircle {

public static void main(String [] args)
{
Circle bc = new Circle("blue", 3.4);
Circle gc = new Circle("green", 2.22);
Circle rc = new Circle();

System.out.println(rc.getColor());
System.out.println(gc.getRadius());

Circle [] ca1 = new Circle[]{bc, gc, rc};
System.out.println(Circle.containsColor("red", ca1));

Circle [] ca2 = new Circle[]{bc, gc, bc, gc};
System.out.println(Circle.containsColor("red", ca2));
System.out.println(Circle.containsColor("green", ca2));
}
}```  Reply With Quote

2. ## Re: Why is the logic not correct?

What is the if statement comparing?  Reply With Quote

3. Member Join Date
Jan 2015
Posts
48
Rep Power
0

## Re: Why is the logic not correct?

That's where I'm having trouble with..  Reply With Quote

4. ## Re: Why is the logic not correct?

Yes, Can you explain what objects the code is comparing?
What is the data type of the two objects being compare?  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•