"possible loss of precision", except not, code doesn't work, simple question
Hello,
I'm trying to make my array as compact as possible. since a calculation will not go above 60, i used byte data type, but the compiler says 'possible loss of precision' and then doesn't run the array. Here is the code fragment:
Code :
tarray=new byte[6][10];
for(byte y=0;y<6;y++){
for(byte x=0;x<10;x++){
tarray[y][x]=(y*10)+x;
System.out.println("tilearray "+y+","+x+": "+tarray[y][x]);
}
}
The following very similar code has the same error, but outputs the value:
Code :
byte six=6;
byte ten=10;
byte mul=six*ten;
System.out.println(mul);
So why doesn't my array output the information.
Re: "possible loss of precision", except not, code doesn't work, simple question
Tell the compiler you know what you are doing by casting the int result to byte:
int var = (byte) (int expression here);
Re: "possible loss of precision", except not, code doesn't work, simple question
thank you Norm, it's fixed