Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ejercicios;
- public class yoqese2 {
- //ejercicio 3 pagina 167.
- public static void crear_array(int[]a){
- int aux=0;
- int longitud=0;
- for(int i=0; i<a.length-1;i++){
- for(int j=0; j<a.length-1-i; i++){
- if (a[i]==a[j]){
- //numero de repeticiones, se le resta a la longitud de a para hacer un nuevo array con los elementos no repetidos.
- aux+=1;
- longitud=a.length-aux;
- // hago a[j]=-1 para diferenciarlo
- a[j]=-1;
- }
- }
- }
- int [] nuevo= new int[longitud];
- for(int i=0; i<a.length-1;i++){
- if(a[i]!=-1){
- nuevo[i]= a[i];
- System.out.println(nuevo[i]);
- }
- }
- }
- public static void main(String[]args){
- int[]array= {1,2,3,3,5,7,8,8,9,2};
- crear_array(array);
- }
- }
Add Comment
Please, Sign In to add comment