“noob in java: java syntax” 翻译为中文:Java中的新手:Java语法

huangapple go评论97阅读模式
英文:

noob in java: java syntax

问题

The first line using the && operator is giving me an error that says "Illegal start of expression."

第一行使用&&运算符时出现错误,错误信息为“表达式的起始无效”。

英文:
  1. if (valid(num1,base)) && (valid(num2,base)){
  2. while(num1>0 || num2>0){
  3. String d1 = extractDigit(num1);
  4. String d2 = extractDigit(num2);
  5. num1 = removeDigit(num1);
  6. num2 = removeDigit(num2);
  7. String d3 = d1 + d2;
  8. if (d3 >= Integer.parseInt(base)){
  9. carry = d3/Integer.parseInt(base);
  10. d3 = d3 % Integer.parseInt(base);
  11. }
  12. else{
  13. carry = 0;
  14. }
  15. ans = makeAns(ans, idx, d3);
  16. idx = idx + 1;
  17. }
  18. if (carry > 0){
  19. ans = makeAns(ans,idx,carry);
  20. }
  21. return ans;
  22. }else{
  23. return "Invalid input";
  24. }

the first line using the && operator is giving me an error that say 'Illegal start of expression'

答案1

得分: 2

你在那一行中有太多的括号。

应该是

整个if语句需要在条件周围加上括号,就像你在其他if和while语句中所做的那样。

英文:

You have too many parentheses in that line.

  1. if (valid(num1,base)) && (valid(num2,base)){

should be

  1. if (valid(num1,base) && valid(num2,base)){

The entire if statement requires parens around the conditional, like you've done in your other if & while statements

huangapple
  • 本文由 发表于 2020年8月9日 09:06:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63321568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定