fork 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 int[] ampliarArray(int[] umArray, int fator)
  11. {
  12. int oldLength = umArray.length;
  13. int newLength = (oldLength + 1);
  14. int[] newArray = new int[newLength];
  15. for(int i = 0; i < oldLength; i++)
  16. {
  17. newArray[i] = umArray[i];
  18. }
  19. newArray[oldLength] = fator;
  20. return newArray;
  21. }
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. int[] array = {1,2,3,4,5};
  25. for(int i = 0; i < array.length; i++)
  26. {
  27. System.out.print(array[i]);
  28. System.out.print(' ');
  29. }
  30. System.out.println();
  31. System.out.println();
  32. array = ampliarArray(array, 6);
  33. for(int i = 0; i < array.length; i++)
  34. {
  35. System.out.print(array[i]);
  36. System.out.print(' ');
  37. }
  38. }
  39. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
1 2 3 4 5 

1 2 3 4 5 6