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

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

noob in java: java syntax

问题

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

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

英文:
if (valid(num1,base)) && (valid(num2,base)){
      while(num1>0 || num2>0){
        String d1 = extractDigit(num1);
        String d2 = extractDigit(num2);
        num1 = removeDigit(num1);
        num2 = removeDigit(num2);
        String d3 = d1 + d2;
        if (d3 >= Integer.parseInt(base)){
          carry = d3/Integer.parseInt(base);
          d3 = d3 % Integer.parseInt(base);
        }
        else{
          carry = 0;
        }
        ans = makeAns(ans, idx, d3);
        idx = idx + 1;
      }
      if (carry > 0){
        ans = makeAns(ans,idx,carry);
      }
      return ans;
    }else{
      return "Invalid input";
    }

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.

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

should be

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:

确定