Can we use float,double,long data type values for array index?
class Array12
{
public static void main(String[] args)
{
int[] x=new int[5];
x[0]=10;
x[1.5]=20;
x[2L]=30;
x[3]=40;
x[4]=50;
for(int a:x)
System.out.println(a);
}
}
/*
Output:- CE[possible loss of precision]
Explanation:- Only 4 data types(char,byte,short,int) are allowed in array index.
*/
{
public static void main(String[] args)
{
int[] x=new int[5];
x[0]=10;
x[1.5]=20;
x[2L]=30;
x[3]=40;
x[4]=50;
for(int a:x)
System.out.println(a);
}
}
/*
Output:- CE[possible loss of precision]
Explanation:- Only 4 data types(char,byte,short,int) are allowed in array index.
*/
0 comments: