Guest User

Untitled

a guest
Feb 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class myClass {
  2.  
  3. /** this method sets the newArray's size to be the sum of the 2 other arrays
  4. * and assigns to the newArray's components the values of the other 2 arrays together
  5. * first param1 and then param2
  6. */
  7.  
  8. public static double[] append(double[] param1, double[] param2) {
  9.  
  10. double[] newArray = new double[param1.length + param2.length];
  11. for (int i = 0; i < newArray.length; i++) {
  12. if (i < 3) {
  13. newArray[i] = param1[i];
  14. } else {
  15. newArray[i] = param2[i-3];
  16. }
  17. }
  18. return newArray;
  19. }
  20.  
  21. /** this method prints out the array **/
  22.  
  23. public static void printValues(double[] values){
  24.  
  25. System.out.print("[");
  26. for (int j=0; j<values.length-1; j++){
  27. System.out.print(values[j]);
  28. System.out.print(", ");
  29. }
  30. System.out.print(values[values.length-1]);
  31. System.out.print("]");
  32. }
  33.  
  34.  
  35. public static void main(String[] args){
  36. double[] array1 = {2,3,7};
  37. double[] array2 = {4,2,6};
  38. double[] appended = append(array1, array2);
  39. printValues(appended);
  40. }
  41. }
Add Comment
Please, Sign In to add comment