Array is one type of data that consists of several elements or a set of values from a set of similar variables. For more details, see the following program code:
See The Code :
So after we compile will generate output like this:public class InitArray
{
public static void main( String args[] )
{
int array[] = new int[ 10 ];
System.out.printf( "Index\tValue" );
for ( int counter = 0; counter < array.length; counter++ )
{
System.out.printf( counter + “\t”+array[ counter ]);
}
}
}
See The Output Code :
Index ValueThe above example is an array that has not been rated yet, so any index in the array will contain the value 0 by Java, well then we will discuss about how to assign values to the array, consider the example program below:
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
Se e The Code :
public class InitArraySo when we compile, the output array is no longer value 0, because already we fill the value in it, note the following output:
{
public static void main( String args[] )
{
int array[] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
System.out.printf( "Index\tValue" );
for ( int counter = 0; counter < array.length; counter++ )
{
System.out.printf( counter + “\t”+array[ counter ]);
}
}
}
See The Output Code :
Index ValueHopefully Useful
0 32
1 27
2 64
3 18
4 95
5 14
6 90
7 70
8 60
9 37
0 comments on Java Tips- Array With Java :
Post a Comment and Don't Spam!
Dont Spam please