Bei dem Array handelt es sich um ein array des Datentyps boolean aus einer anderen Klasse (GanzZahl). In dem Array sind nur true und false drin gespeichert und ich will in der if-Anweisung prüfen ob an der Stelle s true oder false steht. Als Fehlermeldung kommt bei dem immer: array required, but int found.
Ich bin noch ziemlich am Anfang, von daher könnte der Fehler ziemlich offensichtlich sein, wäre gut wenn mir jemand helfen könnte
Code in der Klasse GanzZahl:
Ich bin noch ziemlich am Anfang, von daher könnte der Fehler ziemlich offensichtlich sein, wäre gut wenn mir jemand helfen könnte
Java:
public void gibPrimzahlen()
{
GanzZahl = new GanzZahl();
GanzZahl.gibPrimzahlen();
for (int s=0; s<101; s++)
{
if (GanzZahl.allePrimzahlen[s]==true)
{
System.out.println(""+s+" ist eine Primzahl");
}
}
}
Code in der Klasse GanzZahl:
Java:
public boolean [] gibPrimzahlen()
{
boolean [] allePrimzahlen = new boolean [101];
int l = 0;
int s = 0;
for (int z=2; z<l; z++)
{
if (l%z==0)
{
allePrimzahlen[l]=false;
}
}
allePrimzahlen[0]=false;
allePrimzahlen[1]=false;
l++;
return allePrimzahlen;
}
Zuletzt bearbeitet: