int data={42,15,27,20,19};
If you compile this, you will see the following error message:
illegal initializer for int
int data={42,15,27,20,19};
^
Here the array is not declared properly as we have not put [ ] for declaring the array. The correct code is:
int data[ ]={42,15,27,20,19};
or
int[ ] data={42,15,27,20,19};
What about String[] x = {{"NewDelhi","Rs"},
ReplyDelete{"Islamabad","Rs"},
{"London","Euro"},
{"Washington","Dollar"}};
It is also producing same error. . .
Reason. . . ????
Here two dimensional String values are assigned to one dimensional array.
ReplyDeleteCorrect code will be:
String[][] x = {{"NewDelhi","Rs"},
{"Islamabad","Rs"},
{"London","Euro"},
{"Washington","Dollar"}};
~/workspace/java/ $ javac TestArray.java
ReplyDeleteTestArray.java:11: error: illegal initializer for int
for (int i = {2,4,6,8,10}; i == myList.length; i++) {
^
1 error
Help me need help
DeleteCorrect code would be:
Deletefor(int i = 0; i<myList.length; i++)
{}
ReplyDeletewhere is the int code ????????
ReplyDelete