Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
- List<Integer> list = new ArrayList<>();
- for (int n : nums1) list.add(n);
- for (int n : nums2) list.add(n);
- Collections.sort(list);
- if(list.size()%2==0){
- return (double)(list.get(list.size()/2-1) + (double)list.get(list.size()/2)) /2;
- }
- else{
- return (double)list.get(list.size()/2);
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] ar1 = sc.nextLine().split(",");
- String[] ar2 = sc.nextLine().split(",");
- int[] nums1 = new int[ar1.length];
- int[] nums2 = new int[ar2.length];
- for (int i = 0; i < nums1.length; i++) {
- nums1[i] = Integer.parseInt(ar1[i]);
- }
- for (int i = 0; i < nums2.length; i++) {
- nums2[i] = Integer.parseInt(ar2[i]);
- }
- System.out.println(findMedianSortedArrays(nums1, nums2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement