DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    9

    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

  2. #2
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    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);
            }
        }
    }

  3. #3
    Join Date
    Feb 2006
    Posts
    9
    Thanks that works.

  4. #4
    Join Date
    Dec 2005
    Location
    New Jersey
    Posts
    290
    Yes, but do you understand it? If not, please ask.

Similar Threads

  1. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  2. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  3. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 10:50 PM
  4. NetUserEnum Api
    By Mike in forum VB Classic
    Replies: 2
    Last Post: 04-24-2000, 03:30 PM
  5. NetUserEnum Api
    By Mike in forum VB Classic
    Replies: 0
    Last Post: 04-24-2000, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links