package com.codegym.task.task01.task0136;
/*
Even to the moon!
*/
public class Solution {
public static void main(String[] args) {
System.out.println(getWeight(888));
}
public static double getWeight(int earthWeight) {
// write your code here
return double moonWeight = earthWeight * 0.17;
}
}
Why can't I "return double moonWeight = earthWeight * 0.17;"?
Resolved
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
ion
9 May 2019, 17:16useful
If you want to do operations with variables then they have to be the same type i.e: integer with integer, double with double etc. You can't mix them. In your case you can write :
return double moonWeight = (double)earthWeight * 0.17;
it makes the integer to look like a double just only for the operation.
+2
smile
10 May 2019, 01:31
"If you want to do operations with variables then they have to be the same type i.e: integer with integer, double with double etc." I see. Thank you.
+2
Raivo Lapiņš
8 May 2019, 10:56solution
Basically what you are trying to do is declare and initialize a new variable and then return it. You can't do it that way.
Either you can do as the first guy already told you to do or you can do it a bit differently and maybe a bit more novice friendly:
+4
Guadalupe Gagnon
7 May 2019, 23:51solution
Because that code is invalid. You can return this though:
+5
smile
8 May 2019, 00:13
It works. Thank you.
+2