Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-01-2007, 02:04 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Rep Power: 0
Albert is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-01-2007, 02:08 AM
Member
 
Join Date: Jun 2007
Posts: 92
Rep Power: 0
Marcus is on a distinguished road
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.

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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-01-2007, 02:13 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Rep Power: 0
Albert is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
array problem oceansdepth New To Java 3 04-05-2008 03:25 AM
Array problem.. help needed please! SCS17 New To Java 3 03-06-2008 11:30 PM
Array List Problem khamuruddeen New To Java 1 12-22-2007 09:10 AM
array problem wats New To Java 1 12-12-2007 08:08 AM
Problem with array Copy coco New To Java 1 08-07-2007 08:46 AM


All times are GMT +2. The time now is 04:52 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org