Results 1 to 3 of 3

Thread: array problem

  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default array problem

    Hi, basically i have a 2D array 6x8 which holds integers i need to get a total for each row - can anyone help please??!!!?

    Thank you

    Albert:rolleyes:

  2. #2
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    A total of what for which row? I'm assuming you want to add up all of the integers in the first row...then the total of all the integers in the second, etc.

    First how would you do this on paper? Write out your algorithm and then try and translate it into java.

    For a hint, here is some code that will print everything in your 2d array.

    Java Code:
    //assume foo is an int [][] array initilized earlier. 
     
     for(int i=0;i<array.length;i++)
     {
        System.out.println("Printing the data in row "+i);
        for(int j=0;j<array[i].length;j++)
        {
            System.out.println("Value at array["+i+"]["+j+"] is "+array[i][j]);
        }	
        System.out.println("moving to next row");
     }
    Marcus:cool:

  3. #3
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default

    This is what i want to do, in pseudo code:

    for each row i in the 2d array // that is for each student
    set the total for the ith student to be 0
    for each column j in the row // that is for each mark for the ith student
    add the mark stored at row i column j to the total for the ith student // something like total += marks[i][j]
    end for // where marks is the 2d array
    output the total for the ith student
    calculate and output the grade for the ith student
    end for

    I just cant put it in java.
    Thanks.

    Albert:rolleyes:

Similar Threads

  1. array problem
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-05-2008, 02:25 AM
  2. Array problem.. help needed please!
    By SCS17 in forum New To Java
    Replies: 3
    Last Post: 03-06-2008, 10:30 PM
  3. Array List Problem
    By khamuruddeen in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 08:10 AM
  4. array problem
    By wats in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:08 AM
  5. Problem with array Copy
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •