Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: PRINTING 2D ARRAY

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post PRINTING 2D ARRAY

    public class odd_Even {
    public static void main(String [] args){

    Scanner sc=new Scanner(System.in);
    System.out.println("Number of rows");
    int rows=sc.nextInt();
    System.out.println("Number of Coulum");
    int col =sc.nextInt();
    int [][] array = new int[rows][col];
    for (int i=0;i <rows;i++ ){
    for (int j=0;j < col; j++){
    array[i][j] =i+j;
    }
    }
    System.out.println(array.toString());

    }

    }

    I want TO PRINT ALL THE ARRAY BUT UNABLE TO DO SO, HOW CAN I DO?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: PRINTING 2D ARRAY

    UNABLE TO DO SO
    Please explain. Post any output that shows what you are talking about.
    If you are getting any error messages, please copy the full text of any error messages and post it here.

    The Arrays class's toString() method useful for printing an array's contents:
      System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PRINTING 2D ARRAY

    well no error but getting something like hash i am getting I@3b95a09c

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,404
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: PRINTING 2D ARRAY

    i am getting I@3b95a09c
    That looks like the String returned by the default toString method.

    Did you try using the Arrays class's method I suggested?
    For a two dim array use the deepToString method.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Printing an array.
    By LoganC in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2012, 04:31 AM
  2. Printing 2d array
    By nWeid1 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 29th, 2012, 08:41 PM
  3. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  4. Printing an array
    By native in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 16th, 2011, 09:07 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM

Tags for this Thread