How to divide an array into half in java?
Answers
Answered by
2
class SplitArray {
// Function to split array into two parts in Java. public static void main(String[] args) {
int[] inp = { 1, 2, 3, 4, 5 }; int n = inp. length;
int[] a = new int[(n + 1)/2]; int[] b = new int[n - a. length];
for (int i = 0; i < n; i++) { if (i < a. ...
a[i] = inp[i]; else. b[i - a. ...
} System. ...
System. out.
Similar questions