The error shows this line
if ((a[0] & 1 == 0) && (a[1] & 1== 0) && (a[2] & 1== 0)){
This is the whole code:
public class Ex4 { public static void main(String[] args) { int [] a = new int [3]; if(args.length == 3) { try{ for(int i = 0; i < args.length; i++) { a[i] = Integer.parseInt(args[i]); } } catch(NumberFormatException e){ System.out.println("Wrong Argument"); } if ((a[0] & 1 == 0) && (a[1] & 1== 0) && (a[2] & 1== 0)){ System.out.println("yes"); } else { System.out.println("no"); } } else{ System.out.println("Error"); } } }
I've fixed the code:
if ((a[0] & 1) == 0 && (a[1] & 1) == 0 && (a[2] & 1) == 0){
Was an issue with the brackets, updated for anyone in the future.
Java doesn't support using the + operator for anything but primitive numeric types and Strings . Here, you can't use the + operator between any arbitrary objects.
A binary operator is an operator that operates on two operands and manipulates them to return a result. Operators are represented by special characters or by keywords and provide an easy way to compare numerical values or character strings. Binary operators are presented in the form: Operand1 Operator Operand2.
==
has higher precedence than &
. You might want to wrap your operations in ()
to specify how you want your operands to bind to the operators.
((a[0] & 1) == 0)
Similarly for all parts of the if
condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With