Variable type changes (Java)

0

Good morning. I work with NetBeans and Java 8. I have a little problem with regard to java variables, more specifically when it comes to changing type. For example, when I define an int and I want to change it to double , it does not work even if using, int a = 3; double b = (double) a; Also, I tested the code in the SoloLearn interpreter and it worked, which makes me wonder. Is one of the two interpreters obsolete?

    
asked by Vyber90 09.08.2017 в 11:15
source

1 answer

1

I do not know if it is obsolete or not, however I leave you some options that I found:

Opcion 1: (haciendo un cast)
int i;
Math.sqrt((double)i)

Opcion 2: (multiplicando por 1.0)
int i; 
double r; 
r = i*1.0;

Opcion 3: (un poco lo que hiciste tu, parecido)
int entero;
double coma;

coma=(double)entero/100; 

Try some of those ways to see if it works for you and tell me if it's solved.

    
answered by 09.08.2017 / 13:04
source