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: Need to know if the Answer is correct?

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need to know if the Answer is correct?

    Hi everyone,
    I need to know if my following answer is right according to the Question. Thanks in advance!

    Write the Java code of the method Transpose2D that takes one 2-dimentional array (matrix) A and returns one 2-dimentional array B that is transpose of matrix A. (assume that all the rows are of the same length)

    public int[][] transpose (int[][] array) {
      if (array == null || array.length == 0)//empty or unset array, nothing do to here
        return array;
     
      int width = array.length;
      int height = array[0].length;
     
      int[][] array_new = new int[height][width];
     
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          array_new[y][x] = array[x][y];
        }
      }
      return array_new;
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need to know if the Answer is correct?

    What happens when the code is compiled and executed? Is the output correct?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Answer me !
    By johnmecanse34 in forum Java Networking
    Replies: 2
    Last Post: November 20th, 2013, 06:12 AM
  2. Replies: 3
    Last Post: March 9th, 2013, 07:22 PM
  3. What's ur answer?
    By Tanmaysinha in forum The Cafe
    Replies: 6
    Last Post: October 12th, 2011, 06:26 AM
  4. need answer for these
    By satishbs in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2011, 01:46 AM
  5. Arrays.equals not returning correct answer.
    By Anyone in forum Collections and Generics
    Replies: 2
    Last Post: February 11th, 2010, 10:12 AM

Tags for this Thread