fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int[] arrFirst = {1,3,5};
  13. int[] arrSecond = {4,7,9};
  14.  
  15. int[] result = new int[arrFirst.length+arrSecond.length];
  16. int firstIndex = 0;
  17. int secondIndex = 0;
  18. for(int i=0; i< result.length;i++) {
  19. if(firstIndex >= arrFirst.length){
  20. result[i] = arrSecond[secondIndex];
  21. secondIndex += 1;
  22. }else if(secondIndex >= arrSecond.length){
  23. result[i] = arrFirst[firstIndex];
  24. firstIndex += 1;
  25. }else if( arrFirst[firstIndex]<arrSecond[secondIndex]){
  26. result[i] = arrFirst[firstIndex];
  27. firstIndex += 1;
  28. }else{
  29. result[i] = arrSecond[secondIndex];
  30. secondIndex += 1;
  31. }
  32. }
  33. for(int i=0; i< result.length;i++) { System.out.print(result[i]); }
  34. }
  35. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
134579