+ 2
any one tell what is the error in this line.It shows error "int cannot be dereferenced". for(i=0;i<=a[i].length();i++)
Java
3 Answers
+ 1
is "a" an String array? đ
was "i" defined before?
the error could be somewhere else so atleast share the 5 lines before too ...
try maybe if i wasn't defined before:
for(int i=0;i<=a[i].length();i++){
0
public class Program
{
public static void main(String[] args) {
int i;
int a[]={4,3,5,2,6,1,7,9,8,10};
for(i=0;i<=a[i].length();i++){
System.out.println(a[i]);
}
}
}
This is the program. please any one find what is the error here. it shows int cannot be dereferenced
0
ah yes a is not an String array so thats the error...
when you do a[i].length() you are trying to call the length() method of an int which is not possible...
only Strings have that method.
arrays have the attribute length which is diffrent and a bit confusing ...
are you trying to print all numbers in the array?
if so that would be this:
int[] a = {4,3,5,2,6,1,7,9,8,10};
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}