Problem:
Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements.
middleWay({1, 2, 3}, {4, 5, 6}) → {2, 5}
middleWay({7, 7, 7}, {3, 8, 0}) → {7, 8}
middleWay({5, 2, 9}, {1, 4, 5}) → {2, 4}
Solution:
public int[] middleWay(int[] a, int[] b) { int[] myArray = new int[] {a[1], b[1]}; return myArray; }
public int[] middleWay(int[] a, int[] b)
ReplyDelete{
int c[] = new int[2];
c[0] = a[1];
c[1] = b[1];
return c;
}
BOB IS COOL!!!!
ReplyDeletepublic int[] middleWay(int[] a, int[] b) {
ReplyDeletereturn new int[] {a[1], b[1]};
}
public int[] middleWay(int[] a, int[] b) {
ReplyDeleteint midA= a.length/2;
int midB =b.length/2;
return new int[] {a[midA],b[midB]};
}
public int[] middleWay(int[] a, int[] b) {
ReplyDeleteint [] arr = new int [] {a[a.length-2], b[b.length-2]};
return arr;
}
public int[] middleWay(int[] a, int[] b) {
ReplyDeletereturn (new int[] {a[1],b[1]});
}