-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAX_END.java
More file actions
38 lines (33 loc) · 870 Bytes
/
MAX_END.java
File metadata and controls
38 lines (33 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Given an array of ints length 3, figure out which is larger, the first or last element in the array,
and set all the other elements to be that value. Return the changed array.
maxEnd3([1, 2, 3]) → [3, 3, 3]
maxEnd3([11, 5, 9]) → [11, 11, 11]
maxEnd3([2, 11, 3]) → [3, 3, 3]
*/
package school;
import java.util.Arrays;
public class MAX_END {
public static void main(String [] args){
int[] nums = {1,2,3};
int[] answer = maxEnd3(nums);
System.out.println(Arrays.toString(answer));
}
public static int[] maxEnd3(int[] nums) {
int[] answer = new int[3];
int num1 = nums[0];
int num2 = nums[2];
if(num1>num2){
nums[2] = nums[0];
nums[1] = nums[0];
return nums;
}else if(num2>num1){
nums[0] = nums[2];
nums[1] = nums[2];
return nums;
}else{
nums[1] = nums[0];
return nums;
}
}
}