-
Help printing out 2 dim array row.
int[][] A={1,2,3,4},
{2,3,4,5},
{3,4,5,6}};
for(i=0; i<3; i++){
for(j=0; j<4; j++){
System.out.print(A[i][j] "\t");
}
System.out.println();
PLEASE HELP
Trying to find out what i can do to get an output with the total row on the right side for example
Total
1 2 3 4 10
2 3 4 5 14
3 4 5 6 18
-
You could do something like:
Code:
int[][] array = new int[][] {
{ 1, 2, 3, 4 },
{ 2, 3, 4, 5 },
{ 3, 4, 5, 6 }
};
for (int i = 0; i < array.length; i++) {
int sum = 0;
for (int j = 0; j < array[i].length; j++) {
sum += array[i][j];
System.out.print(array[i][j] + " ");
if (j == array[i].length - 1) {
System.out.println(sum);
}
}
}
-
-
Yes, but do you understand it? If not, please ask.
Similar Threads
-
Replies: 146
Last Post: 08-12-2002, 10:40 PM
-
By Rob Teixeira in forum .NET
Replies: 129
Last Post: 06-06-2002, 05:23 AM
-
By Patrick Comeau in forum VB Classic
Replies: 6
Last Post: 03-22-2001, 10:50 PM
-
By Mike in forum VB Classic
Replies: 2
Last Post: 04-24-2000, 03:30 PM
-
By Mike in forum VB Classic
Replies: 0
Last Post: 04-24-2000, 03:05 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|