die Aufgabe scheint so (Schreiben Sie ein Programm Plateau, welches eine beliebige Anzahl ganzer Zahlen (positiv und negativ) entgegennimmt und sowohl die Position, als auch die Länge des längsten Plateaus innerhalb dieser Werte bestimmt. Als Plateau wird eine zusammenhängende Folge gleicher Werte bezeichnet, wobei die Werte direkt vor und direkt nach dieser Folge kleiner sind).
ich bekomme eine Fehler (Index 0 out of bounds for length 0 ).
ich bekomme eine Fehler (Index 0 out of bounds for length 0 ).
Java:
public class Plateau
{
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
int argument = args.length;
int [] array = new int [N];
int new_length=0;
int location=0;
int max=0;
int current_length=0;
if(argument < 2)
{
System.out.println("ERROR: Bitte mehr als 2 Zahlen angeben");
return;
}else{
System.out.println("Kein Plateau");
}
for (int i=0; i < N; i++){
int number = Integer.parseInt(args[i]);
array [i] = number;
}
int compare=array[0];
for (int l=0; l<N; l++){
if (array[l] < compare){
current_length=0;
compare = array[l];
}
else if (array[l] == compare){
current_length+=1;
compare = array[l];
}
else if (array[l] > compare){
compare=array[l];
l++;
}
compare= array[l];
for (int b=0; b<N; b++){
if (current_length > max){
max = current_length;
location = array[l];
new_length=max-1;
}
else if (current_length==1){
new_length=max;
}
}
}
System.out.println(location);
System.out.println(new_length);
}
}
Zuletzt bearbeitet von einem Moderator: