Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Creating a method arrayModifier(int[] a) which takes an integer array of length n, where n > 5. The method returns an integer array of length 10 where the first 1/2 of the array contains elements from the start of the input array and the second 1/2 of the array contains elements from the end of the input array.
- I'm not 100% sure how to start any help would be great !
- My test case:
- int[] a = {4, 5, 6, 7, 8, 9};
- System.out.println(Arrays.toString(arrayModifier(a)))
- output:
- [4, 5, 6, 7, 8, 5, 6, 7, 8, 9]
- Another test case:
- int[] a = {23, 43, 23, 56, 78, 95, 67, 24, 15, 28, 37, 48, 66};
- System.out.println(Arrays.toString(arrayModifier(a)))
- output:
- [23, 43, 23, 56, 78, 15, 28, 37, 48, 66]
- Code:
- public static int[] arrayModifier(int[] a) {
- int ctr = 0;
- int i=0;
- for(int i = 0;i<a.length;i++){
- {
- if(a[i] >= 5) {
- a[i] = a[10];
- ctr ++;
- }
- }
- return ctr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement