-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxEnd3.java
45 lines (41 loc) · 1.46 KB
/
maxEnd3.java
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
39
40
41
42
43
44
45
/**
* 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.
*
* @author (artimre098)
* @version (9/25/17)
*/
import java.util.*;
public class maxEnd3
{
public static void main(String [] args){
int arr[] = new int [3];
Scanner in = new Scanner(System.in);
System.out.println("input elements");
for(int x = 0; x < arr.length ; x ++){
System.out.print("input > ");
arr[x] = in.nextInt();
}
System.out.print('\u000C'); // to clear the screen
System.out.print("Array: ");
for(int x = 0; x < arr.length ; x ++){ // to output the elements of your array
System.out.print(arr[x] + " ");
}
int temp = 0;
if( arr[0] > arr[arr.length-1]){ // always remember that the index always start with 0
temp = arr[0];
System.out.print("\nNew Array: ");
for(int x = 0; x < arr.length ; x ++){
arr[x] = temp;
System.out.print(arr[x] + " " );
}
}else if(arr[0] < arr[arr.length-1]) {
temp = arr[arr.length-1];
System.out.print("New Array: ");
for(int x = 0; x < arr.length ; x ++){
arr[x] = temp;
System.out.print(arr[x] + " " );
}
}
}
}