Āæporque la impresiĆ³n de la siguiente linea (7/2*2.0) da como salida 6? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 5

Āæporque la impresiĆ³n de la siguiente linea (7/2*2.0) da como salida 6?

Al momento de poner la siguiente instrucciĆ³n en java me da como resultado 6: System.out.println(7/2*2.0); Alguien que me explique šŸ™šŸ™šŸ™šŸ™šŸ™šŸ™šŸ™

30th Dec 2017, 7:26 PM
Cmurio
Cmurio - avatar
6 Respostas
+ 4
ohhhh ya entendĆ­, osea la divisiĆ³n se toma como un valor entero de tipo Int y ya despuĆ©s la convierte a tipo flotante por el 2.0 , gracias chavales šŸ‘šŸ‘
30th Dec 2017, 7:42 PM
Cmurio
Cmurio - avatar
+ 4
(7/2*2.0) because the precedence of division is greater so first division perform which give 3 then it multiply 3 with 2 and output came as 6 7/2=3 3*2.0=6.0 so output is 6
30th Dec 2017, 7:34 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
7/2*2.0 (int/int*double) -> int 7/2 = 3 (/ means division w/o remainders) 3*2.0 = 6 (3 multiplied by 2 is 6 Therefore: 7/2*2 0 = 6 (I'm not spanish but I can understand a little spanish)
31st Dec 2017, 2:18 AM
Raphael Salupan
Raphael Salupan - avatar
+ 2
System.out.println(7/2*2.0); es lo mismo que System.out.println((7/2)*2.0); osea, hace la divisiĆ³n que es 3 y la multiplica por 2.0 y eso da 6.0
30th Dec 2017, 7:35 PM
Daniel
Daniel - avatar
+ 1
Lo que tu quieres hacer quizĆ”s es esto System.out.println(7/(2*2.0)); que da algo distinto porque multiplica abajo y despuĆ©s hace la divisiĆ³n
30th Dec 2017, 7:33 PM
Daniel
Daniel - avatar
0
el tipo por defecto de los nĆŗmeros en java es int y por tanto hace el floor de la divisiĆ³n 7/2 = 3 7.0/2 = 3.5
18th Aug 2021, 11:46 PM
David OrdƔs
David OrdƔs - avatar