java - printing all the array value -


class arrayapp{      public static void main(final string[] args){       long [] arr;       arr= new long[100];      int i;      arr[0]=112;      arr[1]=111;      for(i=0;i<arr;i++) {      system.out.println(arr[i]);      }    }  }  

i error,

arrayapp.java:10: operator < cannot applied int,long[]         for(i=0;i<arr;i++) {                  ^ 

you need use size of array, arr.length.

for (int = 0; < arr.length; ++i) 

as of java 1.5, can use each loop if need access array data.

for ( long l : arr ) {     system.out.println(l); } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -