Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class myClass {
- /** this method sets the newArray's size to be the sum of the 2 other arrays
- * and assigns to the newArray's components the values of the other 2 arrays together
- * first param1 and then param2
- */
- public static double[] append(double[] param1, double[] param2) {
- double[] newArray = new double[param1.length + param2.length];
- for (int i = 0; i < newArray.length; i++) {
- if (i < 3) {
- newArray[i] = param1[i];
- } else {
- newArray[i] = param2[i-3];
- }
- }
- return newArray;
- }
- /** this method prints out the array **/
- public static void printValues(double[] values){
- System.out.print("[");
- for (int j=0; j<values.length-1; j++){
- System.out.print(values[j]);
- System.out.print(", ");
- }
- System.out.print(values[values.length-1]);
- System.out.print("]");
- }
- public static void main(String[] args){
- double[] array1 = {2,3,7};
- double[] array2 = {4,2,6};
- double[] appended = append(array1, array2);
- printValues(appended);
- }
- }
Add Comment
Please, Sign In to add comment