Guest User

Untitled

a guest
May 27th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. package Ejercicios;
  2.  
  3. public class yoqese2 {
  4. //ejercicio 3 pagina 167.
  5.  
  6. public static void crear_array(int[]a){
  7. int aux=0;
  8. int longitud=0;
  9.  
  10. for(int i=0; i<a.length-1;i++){
  11. for(int j=0; j<a.length-1-i; i++){
  12. if (a[i]==a[j]){
  13. //numero de repeticiones, se le resta a la longitud de a para hacer un nuevo array con los elementos no repetidos.
  14. aux+=1;
  15. longitud=a.length-aux;
  16. // hago a[j]=-1 para diferenciarlo
  17. a[j]=-1;
  18. }
  19. }
  20. }
  21. int [] nuevo= new int[longitud];
  22. for(int i=0; i<a.length-1;i++){
  23. if(a[i]!=-1){
  24. nuevo[i]= a[i];
  25. System.out.println(nuevo[i]);
  26. }
  27. }
  28.  
  29.  
  30. }
  31.  
  32. public static void main(String[]args){
  33. int[]array= {1,2,3,3,5,7,8,8,9,2};
  34. crear_array(array);
  35. }
  36.  
  37.  
  38.  
  39. }
Add Comment
Please, Sign In to add comment