'Signing up Codewars - Java Exercise
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.
Solution 1:[1]
Here is the answer:
public class Multiply
{
public double multiply(double a, double b)
{ return a * b;}
}
Solution 2:[2]
Think about how it will work if it is executed without any main method and what all things are missing / incorrect format in the code
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);
}
}
Solution 3:[3]
public class Multiply {
public double multiply(double a , double b )
//just change the wrapper to primitive
{
return a*b ;
// add semicolon over here that it
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pika Supports Ukraine |
| Solution 2 | Brydenr |
| Solution 3 | Traian GEICU |
