Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. // The "AddingArrays" class.
  2. // Dave Tsinovoy
  3. // January 28th, 2012
  4. //@param first the first list (array) of numbers
  5. //@param second the second list (array) of numbers
  6. import java.awt.*;
  7. import hsa.Console;
  8.  
  9. public class AddingArrays
  10. {
  11.     static Console c;           // The output console
  12.  
  13.     static int[] addArrays (int[] first, int[] second)
  14.     {
  15.  
  16.         if (first.length > second.length)
  17.         {
  18.             for (int i = 0 ; i < first.length ; i++)
  19.             {
  20.                 int[] newArray = new int [first.length];
  21.                 newArray [i] = first [i] + second [i];
  22.             }
  23.             return newArray;
  24.         }
  25.         else
  26.         {
  27.             for (int i = 0 ; i < second.length ; i++)
  28.             {
  29.                 int[] newArray = new int [second.length];
  30.                 newArray [i] = first [i] + second [i];
  31.             }
  32.             return newArray;
  33.         }
  34.  
  35.     }
  36.  
  37.  
  38.     public static void main (String[] args)
  39.     {
  40.         c = new Console ();
  41.  
  42.         // Place your program here.  'c' is the output console
  43.     } // main method
  44. } // AddingArrays class