Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
Zitat von »"David Scherfgen"«
weißt du, wie viel Platz du wirklich brauchst und machst ein neues Array mit dieser Größe, in welches du das Ergebnis reinkopierst.
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
ArbeitsArray = new bool[GrößeDesEingabeArrays] for(int x = 0; x < GrößeDesEingabeArrays; x++) { for(int y = x + 1; y < GrößeDesEingabeArrays; y++) { if(EingabeArray[x] == EingabeArray[y]) { ArbeitsArray[x] = true ArbeitsArray[y] = true } } } int counter = 0; foreach Element of ArbeitsArray if(ArbeitsArray == true) counter++; AusgabeArray = new int[counter] int x = 0 int counter = 0 foreach Element of ArbeitsArray { if(ArbeitsArray == true) { AusgabeArray[counter] = EingabeArray[x] counter++ } x++ } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
01 public static int[] studentsMethod(final int[] array_in) { 02 03 int counter = 0; 04 for (int i = 0; i < array_in.length; i++) { 05 int toLookFor = array_in[i]; 06 boolean takeIt = false; 07 for (int j = 0; j < array_in.length; j++) 08 if (toLookFor == array_in[j] && i != j) 09 takeIt = true; 10 if (takeIt) 11 counter++; 12 } 13 14 int[] result = new int[counter]; 15 int pointer = 0; 16 17 for (int i = 0; i < array_in.length; i++) { 18 int toLookFor = array_in[i]; 19 boolean takeIt = false; 20 for (int j = 0; j < array_in.length; j++) 21 if (toLookFor == array_in[j] && i != j) 22 takeIt = true; 23 if (takeIt) { 24 result[pointer] = toLookFor; 25 pointer++; 26 } 27 } 28 29 return result; 30 } |
Werbeanzeige