注册 Codewars - Java 练习

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30902556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:48:33  来源:igfitidea点击:

Signing up Codewars - Java Exercise

java

提问by R Jani

The code is

代码是

public class Multiply
{
   public static Double multiply(Double a, Double b)
   {
       return a * b
   }
}

I cannot solve the above code.
I tried a few things, like

我无法解决上面的代码。
我尝试了一些东西,比如

public class Multiply 
{ 
   public double multiply(double a, double b) 
   { return a * b;} 
}

It still shows errors in code.
Kindly help, please.

它仍然显示代码中的错误。
请帮助,请。

回答by nathantspencer

You essentially had the answer Codewars wanted. I imagine they expected for you to just add the semicolon, as you did, but keep the rest of the code the same.

您基本上得到了 Codewars 想要的答案。我想他们希望您像您一样只添加分号,但保持其余代码相同。

public class Multiply
{
   public static Double multiply(Double a, Double b)
   {
       return a * b;
   }
}

I went to try it out, and this worked for me. Looks like they wanted you to keep staticand the wrapper class Double.

我去试试,这对我有用。看起来他们希望你保留static包装类Double

回答by nathantspencer

Here is the answer:

这是答案:

public class Multiply 
{ 
   public double multiply(double a, double b) 
   { return a * b;} 
}

回答by Helper

Think about how it will work if it is executed without any mainmethod and what all things are missing / incorrect format in the code

想想如果它在没有任何main方法的情况下执行,它将如何工作以及代码中缺少什么/格式不正确

E.g. Where you can add any double value

例如,您可以在哪里添加任何双值

public class Multiply {
    public static double multiply(double a, double b) {
        return a * b;
    }

    public static void main(String[] args) {
        double result = multiply(20.01, 10.10);
        System.out.println("The result is: " + result);
    }
}