Virtusa interview question

A & B are two integer arrays. Put their values into new array and sort it. Write an algorithm to do so.

Interview Answer

Anonymous

27 May 2015

package javaapplication6; import java.util.Arrays; import javax.swing.JOptionPane; public class JavaApplication6 { /** * @param args the command line arguments */ public static void main(String[] args) { int array[] = {10,2,1,20,8}; JOptionPane.showMessageDialog(null,"Original Array " +Arrays.toString(array)); JOptionPane.showMessageDialog(null,"Original Array " +Arrays.toString(sort(array))); } /* * public static method for sorting * inputs : integer array * return value integer array */ public static int[] sort(int []array){ int temp; for (int i=0; iarray[j]){ temp= array[j-1]; array[j-1]=array[j]; array[j]=temp; } } } return array; } }

3