+ 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

6th Aug 2019, 10:11 AM
Rema Devi R
3 ответов
+ 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++){
6th Aug 2019, 10:15 AM
Anton Böhler
Anton Böhler - avatar
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
6th Aug 2019, 10:19 AM
Rema Devi R
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]); }
6th Aug 2019, 10:26 AM
Anton Böhler
Anton Böhler - avatar