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 2 of 2

Thread: Problem with returning 2d array

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with returning 2d array

    I got two class a cipher and tester class
    here is cipher:
    import java.util.*;
    import java.lang.*;
    public class Ciph{

    public char[][] getCipherText(){
    char[][] a={{'A','E','B','I','M','Y'},{'N','R','C','A','T', 'S'}};


    return a;
    }
    }

    here is tester:
    public class Test{

    public static void main(String[] args){

    Ciph cph= new Ciph();
    System.out.println(cph.getCipherText());

    }

    }

    There is no error in compiling but when you run the program, it returns random string not the AEBIMYNRCATS
    I get the error: [[C@7a718e31

    How do I solve this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problem with returning 2d array

    I get the error: [[C@7a718e31
    That is not an error. That is the String returned by a two dimensional array's toString() method.
    To get a printout of the array's contents, use the Array class's deepToString() method to format the array:
    System.out.println("an ID "+ java.util.Arrays.deepToString(theArrayName));

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. problem returning array
    By dendoc01 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 2nd, 2013, 06:19 AM
  2. [SOLVED] Returning an array
    By maple1100 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: January 21st, 2013, 02:38 PM
  3. Returning An Array
    By LoganC in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 28th, 2012, 03:57 PM
  4. Having trouble returning an array
    By 93tomh in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 30th, 2012, 11:09 AM
  5. returning a 2D array
    By straw in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2010, 04:30 AM

Tags for this Thread