Pabl0o0

Untitled

Nov 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. public class laborki7 {
  3.  
  4. static void duplicate(int[] array1, int[] array2){
  5.  
  6. if (array2.length<array1.length){
  7. System.out.println("The second array is to small !");
  8. return;
  9. }
  10.  
  11. int[] result;
  12. int result_array_length = 0;
  13. for (int i =0; i< array1.length; i++){
  14. result_array_length += array2[i];
  15. }
  16. result = new int[result_array_length];
  17. int end=0;
  18.  
  19. for(int i=0; i<array1.length; i++)
  20. {
  21. for(int j=0; j<array2[i];j++)
  22. {
  23. result[end]=array1[i];
  24. end++;
  25. }
  26. }
  27.  
  28. for(int i:result)
  29. {
  30. System.out.print(i);
  31. System.out.print(", ");
  32. }
  33. }
  34.  
  35. public static void main(String args[]){
  36. int[] array1={1,2,3};
  37. int[] array2={0,5,3,4};
  38. duplicate(array1,array2);
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment