0

What does this mean in java ?

ERROR : incompatible types: void cannot be converted to double public class otherCLASS { static void DIVIDEby2(double divide) { divide=divide/2; System.out.println(divide) ; } But when write the code like this,then there is no error public class otherCLASS { static double DIVIDEby2(double divide) { divide=divide/2; return divide ; } EDIT : main method public static void main(String[]args) { double y = 100; double w = DIVIDEby2(y); System.out.println(y); System.out.println(w); }

15th Apr 2020, 11:06 AM
H-J
H-J - avatar
3 Réponses
+ 1
void method return nothing.. so,when u use the first method,and want to assign it to double w,u try to cast/convert "nothing" to a double. since there is nothing to convert,it gives error but the second one returns double,so it runs normally
15th Apr 2020, 11:23 AM
durian
durian - avatar
0
how did u use that method in main?
15th Apr 2020, 11:10 AM
durian
durian - avatar
0
@Lily Mea Thanks.
15th Apr 2020, 11:52 AM
H-J
H-J - avatar