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: I need help with my homework

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

    Question I need help with my homework

    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)
    and this my answer
    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;
    }
    is method correct or there an another way to do it


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,346
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: I need help with my homework

    Do you have a description of the algorithm that you are trying to write in java?
    What problems are you have writing a java program to implement that algorithm?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help With my Homework Please :)
    By surfelijo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 17th, 2013, 07:32 PM
  2. Help with homework
    By gta1 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 11th, 2013, 09:58 PM
  3. Homework help
    By hockey15 in forum Object Oriented Programming
    Replies: 3
    Last Post: September 24th, 2012, 12:28 AM
  4. Homework
    By jdonaldson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 11:09 AM