Home  >  Forum  >  Core Java
Post New Query

printing the elements of array in java


joined on
October 13,2014
Asked on March 10,2015
I want to print the all elements of my array list but got these error. please help to fix them. Thanks 
Error:
[I@3b95a09c
[I@3b95a09c
[I@3b95a09c
[I@3b95a09c
[I@3b95a09c
[I@3b95a09c
[I@3b95a09c

My Code is:

public class MyArray {
public static void main(String[] args) {
int [] nums;
nums = new int[7];
nums[0] = 6;
nums[1] = 12;
nums[2] = 13;
nums[3] = 22;
nums[4] = 9;
nums[5] = 33;
nums[6] = 44;
for(int i = 0; i <= 6; i++){
System.out.println(nums);
}
}

}

joined on
March 05,2015
Replied on March 10,2015

for(int i = 0; i <= 6; i++)
{
    System.out.println(nums[i]);
}
joined on
March 27,2014
Replied on March 10,2015

You can also print it as 

for(int i = 0; i < nums.length; i++)
{
    System.out.println(nums[i]);
}

joined on
March 15,2013
Replied on March 11,2015

You have stored your all array element in nums variable and you want to print it, so almost you have done best to print the element using for loop.
for(int i = 0; i <= 6; i++)
When your loop is running then it will store all array element in variable i and your loop will print all element one bye one. Your print statement is like this...
System.out.println(nums[i]);

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us