Total members 11894 |It is currently Fri Nov 22, 2024 7:36 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This code sum array in vertical
Code:
public
   {
       public static void main(String[ ] args)
         {
            int[][] table = { {1,2,3}, {1,2,3}};
            int row, column;
            for (row = 0; row <table.length; row++)
               {
                    for(column = 0; column<table[ row].length; column++)
                         System.out.print( table[row][column]) ;
                   System.out.println( );
               }
            int[] val = sum1(table);
            for(int k=0; k<val.length; k++)
                    System.out.print(val[k]+" ");
         }
 
     public static int
[] sum1 (int[][] numbers)
        {
           int sum[] = new int[numbers[0].length];    /* Change1: set sum[] 's
 length to (numbers[0].length)  */
                       
           for 
(int i = 0; i < numbers[0].length;
i++)                           /*Change 2: change the cond'n */
              {                                                                /
*(
k<numbers.length) to (k<numbers[0].length)  */  
                  int total 
= 0;
                  for (int j = 0; j < numbers.length;
j++)                          /*Change 3: change the cond'n
(k<numbers[0].length) to (k<numbers.length)  */
                  total += numbers[j][i]
;
                                                    //Change 4  : replacce 
[i] each other [j]
                  //System.out.print( total);
                  sum[i]=total;
                  //System.out.println( );
                }
           return sum;
       }
}
 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Adding vertical array in java
 vertical align of the image     -  
 vertical alignment of span tag     -  
 Array Casting in java     -  
 Java Two Dimensional Array     -  
 Need Help with Java Array Sorting Logic     -  
 quicksort algorithm implementation java code- array sorting     -  
 Bubble Sort Algorithm Java Implementation Code-Sorting Array     -  
 adding abbreviations to your html     -  
 Need automatic adding to catalogs     -  
 Adding a New Node to contact.xml     -  



Topic Tags

Java Arrays
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com