-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinMaxArray.java
More file actions
37 lines (35 loc) · 1.07 KB
/
MinMaxArray.java
File metadata and controls
37 lines (35 loc) · 1.07 KB
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
package Codes;
import java.util.Arrays;
import java.util.Scanner;
public class MinMaxArray {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
String[] arraymin=s.split(" ");
String[] arraymax=s.split(" ");
Arrays.sort(arraymin);
for (int i=0;i<arraymax.length;i++){
for (int j=i+1;j<arraymax.length;j++){
if (Integer.parseInt(arraymax[i])<Integer.parseInt(arraymax[j])){
String temp=arraymax[i];
arraymax[i]=arraymax[j];
arraymax[j]=temp;
}
}
}
int[] output=new int[arraymin.length];
int j=0;
for (int i=0;i<output.length;i=i+2){
output[i]=Integer.parseInt(arraymin[j]);
j++;
}
j=0;
for (int x=1;x<output.length;x=x+2){
output[x]=Integer.parseInt(arraymax[j]);
j++;
}
for (int value : output) {
System.out.print(value + " ");
}
}
}