Guten Abend, ich möchte überprüfen, ob ein Wert sich im Array befindet und wenn nicht soll es eine IllegalArgumentException auslösen.
Vielen Dank schonmal für die Hilfe
z.b
int x = 2
ist x im int[] a = {12,7,5,9,13,24} ?
ich wollte es in diese Methode einbauen, in meine if anweisung
Vielen Dank schonmal für die Hilfe
z.b
int x = 2
ist x im int[] a = {12,7,5,9,13,24} ?
ich wollte es in diese Methode einbauen, in meine if anweisung
Java:
public static int next(int[] a, int x){
if(a == null || a.length <= 0){
throw new IllegalArgumentException("keine Werte im Array");
}
int result = 0;
int lange = a.length;
for (int i = 0; i < a.length; i++){
if(...){
throw new IllegalArgumentException("x befindet sich nicht im Array");
}
if(x == a[lange -1]){
result = x;
}
if(a[i] == x && a[lange -1] != x){
result = a[i+1];
}
}
return result;
}