0
How to compare object class to multiple integers?
if(p.getBornyear()==2000) && (p.getBoenyear()==2002) && (p.getBornyear()==2003){ System.out.println("Generation z"); } else { System.out.println("Invalid") } When i enter 2003 the output is invalid i dont know why?
3 Answers
+ 1
Vance Sibonga Pedroso If you want your comparison to be true if your variable has any value within a list, you should use the 'or' operator (||).
But your problem seems to require comparison with a range. Why not something like:
if (var >= minimum && var <= maximum) {
commands;
}
+ 1
Because it's different from 2000 and 2002. Since you're using the 'and' operator (&&), the conditional only gets true if the attribute 'Bornyear' equals 2000, 2002 and 2003 at the same time - that is: never. By the way, watch the typo in the second line.
0
Emerson Prado so what is the best way or method to compare object class to multiple integers like this?