eclipse - Recursive Method in Java, Invalid AssignmentOperator -
i trying use recursive method in java assignment in class. given return each condition, , use test method.
however, keeps telling me (r-1) , (p-1), within if/else statements in method, have invalid assignmentoperator.
i have tried changing return types on method, messed around structure of statements, , on..
here code:
public static void main(string[] args) { recursivealgorithm(0, 0); recursivealgorithm(0, 1); recursivealgorithm(1, 1); recursivealgorithm(1, 2); recursivealgorithm(1, 3); recursivealgorithm(2, 2); recursivealgorithm(3, 2); } public static int recursivealgorithm(int r, int p) { if (r == 0) { return p + 1; } if (p == 0){ return recursivealgorithm(r – 1, 1); } else { return recursivealgorithm(r – 1, recursivealgorithm(r, p – 1)); } }
i have no idea i'm doing wrong, i'm sure has syntax, have no idea else try. very, appreciated.
error:
exception in thread "main" java.lang.error: unresolved compilation problems: syntax error on token "invalid character", invalid assignmentoperator syntax error on token "invalid character", invalid assignmentoperator syntax error on token "invalid character", invalid assignmentoperator @ javaproject.java_recursion.recursivealgorithm(java_recursion.java:25) @ morris_brittany.java_recursion.main(java_recursion.java:7)
do this:
public static void main(string[] args) { recursivealgorithm(0, 0); recursivealgorithm(0, 1); recursivealgorithm(1, 1); recursivealgorithm(1, 2); recursivealgorithm(1, 3); recursivealgorithm(2, 2); recursivealgorithm(3, 2);
}
public static int recursivealgorithm(int r, int p) { if (r == 0) { return p + 1; } if (p == 0){ return recursivealgorithm(r - 1, 1); } else { return recursivealgorithm(r - 1, recursivealgorithm(r, p - 1)); } }
the problem -
different character minus sign on keyboard. have no idea why put kind of character there, eclipse said character not -
can use this , see copy -
, –
see both different.
Comments
Post a Comment