Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program in Java

–2 votes
asked Aug 12, 2019 by Smarak
write a program in Java to take two arrays of size 10 and 20 store values in ascending order merge both the arrays in another array of size 30 in such a way that the values are stored in ascending order

3 Answers

0 votes
answered Aug 16, 2019 by anonymous

mport java.util.*;
import java.lang.*;
import java.io.*;
  
class MergeTwoSorted
{
    // Merge arr1[0..n1-1] and arr2[0..n2-1]  
    // into arr3[0..n1+n2-1]
    public static void mergeArrays(int[] arr1, int[] arr2, int n1,
                                int n2, int[] arr3)
    {
        int i = 0, j = 0, k = 0;
      
        // Traverse both array
        while (i<n1 && j <n2)
        {
            // Check if current element of first
            // array is smaller than current element
            // of second array. If yes, store first
            // array element and increment first array
            // index. Otherwise do same with second array
            if (arr1[i] < arr2[j])
                arr3[k++] = arr1[i++];
            else
                arr3[k++] = arr2[j++];
        }
      
        // Store remaining elements of first array
        while (i < n1)
            arr3[k++] = arr1[i++];
      
        // Store remaining elements of second array
        while (j < n2)
            arr3[k++] = arr2[j++];
    }
      
    public static void main (String[] args)  
    {
        int[] arr1 = {1, 3, 5, 7};
        int n1 = arr1.length;
      
        int[] arr2 = {2, 4, 6, 8};
        int n2 = arr2.length;
      
        int[] arr3 = new int[n1+n2];
          
        mergeArrays(arr1, arr2, n1, n2, arr3);
      
        System.out.println("Array after merging");
        for (int i=0; i < n1+n2; i++)
            System.out.print(arr3[i] + " ");
    }
}

commented Aug 18, 2019 by anonymous
public class apples{

public static void main(String[] args){

System.out.println("hello");

}}
0 votes
answered Aug 16, 2019 by Rajesh Singh
class YouAreFoolish

{

public static void main(String arg[])

{

System.out.println("WOW What a Question... You Are a Genius ");

}

}
0 votes
answered Aug 19, 2019 by Raghul
#include <stdio.h>

int main()
{
    int x,y,z;
    printf("Enter the value of x and y\n");
    scanf("%d %d",&x,&y);
    
    z = (x>y) ? x:y;
    printf("%d",z);
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...