Error | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Error

// package ClassObjectsandMethod; class Methodoperator { static float mul(float x,float y) { return x*y; } static float div(float x,float y) { return x/y; } } public class StaticMember { public static void main(String[] args) { float a = Methodoperator.mul(4.0,5.0); //Why an error here float b = Methodoperator.div(a,5.0); //& here } } Why this error show .... StaticMember.java:15: error: incompatible types: possible lossy conversion from double to float float a = Methodoperator.mul(4.0,5.0); ^ StaticMember.java:16: error: incompatible types: double cannot be converted to Float float b = Methodoperator.div(4.0,5.0); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 2 errors

12th Jun 2020, 11:23 AM
Kriti_shrivastava
Kriti_shrivastava - avatar
5 Respuestas
+ 1
Hello Kriti_shrivastava 4.0 and 5.0 are doubles. You have to add F to each number to treat them as float: float a = Methodoperator.mul(4.0F, 5.0F); float b = Methodoperator.div(4.0F, 5.0F);
12th Jun 2020, 11:39 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Denise Roßberg I try it but it doesn't work Same error show
12th Jun 2020, 11:57 AM
Kriti_shrivastava
Kriti_shrivastava - avatar
+ 1
Kriti_shrivastava Maybe you did something wrong. Here is a code: https://code.sololearn.com/cZdAAzHUOLJ1/?ref=app
12th Jun 2020, 12:03 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
I changed the code. Please check it again.
12th Jun 2020, 12:10 PM
Denise Roßberg
Denise Roßberg - avatar
0
Thank🤗🤗🤗 I got it...
12th Jun 2020, 12:12 PM
Kriti_shrivastava
Kriti_shrivastava - avatar