+ 1

Casting inside of arrays? (JAVA)

Could you implicit or exicitly cast data types inside of arrays in Java? Or would you need to separate the values and then cast them individually?

15th Dec 2019, 10:05 PM
Subject Loser
Subject Loser - avatar
2 Answers
+ 2
Is this what you mean:- float a = 23.54f; float b = 43.654f; float c = 987.67f; int[] myint = {(int)a, (int)b, (int)c}; for(int x: myint) System.out.println(x); int[] myint2 = {(int)43.65, (int)653.643, (int)345.555}; for(int x: myint2) System.out.println(x); float[] myfloat = {43.65f, 653.643f, 345.555f}; for(float x: myfloat) System.out.println((int)x);
15th Dec 2019, 10:31 PM
rodwynnejones
rodwynnejones - avatar