Results 1 to 4 of 4
Thread: Why is the logic not correct?
- 02-12-2015, 10:40 PM #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)); } }
- 02-12-2015, 10:48 PM #2
Re: Why is the logic not correct?
What is the if statement comparing?
If you don't understand my response, don't ignore it, ask a question.
- 02-12-2015, 10:56 PM #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..
- 02-12-2015, 11:06 PM #4
Similar Threads
-
Where's the logic?
By diamonddragon in forum New To JavaReplies: 11Last Post: 01-28-2012, 04:16 AM -
Logic Help
By Barbados in forum New To JavaReplies: 6Last Post: 01-22-2012, 11:24 PM -
Need help on logic
By nn12 in forum New To JavaReplies: 6Last Post: 03-10-2011, 11:06 AM -
need a logic for this
By rajivjoshi in forum New To JavaReplies: 4Last Post: 06-12-2010, 02:18 PM -
Cant get the logic right
By jermaindefoe in forum New To JavaReplies: 4Last Post: 03-11-2008, 12:22 AM
Bookmarks