Ich versuche nur, verschachtelte Schleifen Methode Hauptfunktion aufzurufen. Ich habe 2 Fehler cannot be resolved or is not a field
und the method patternA() is undefined for the type classNested
. Ich weiß, dass es wirklich ein häufiger Fehler ist, aber ich konnte immer noch keinen Weg finden, es zu lösen.Aufruf Methode in Hauptfunktion
Hier ist meine Hauptklasse
package nomerTuhuh;
import java.util.Scanner;
public class nestedLoops {
public static void main(String[] args) {
// get the total number of lines n.
classNested result = new classNested();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of lines:");
result.n=sc.nextInt(); <-- error "cannot be resolved or is not a field"
result.patternA(); <-- error "the method patternA() is undefined for the type classNested"
}
}
Und hier ist die Methode
package nomerTuhuh;
import java.util.Scanner;
public class classNested {
public int n;
void patternA(){
// Loop through the lines from 1 to n
System.out.println("Pattern A");
for (int i = 1; i <= n; i++) {
// Printing number increamentally from 1 to line number j
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
1. Fehler:
Description Resource Path Location Type
n cannot be resolved or is not a field nestedLoops.java /chapter1/src/nomerTuhuh line 14 Java Problem
2. Fehler:
Description Resource Path Location Type
The method patternA() is undefined for the type classNested nestedLoops.java /chapter1/src/nomerTuhuh line 16 Java Problem
Kann mir bitte jemand sagen, was los ist? Vielen Dank.
Wie haben Sie Ihre '.java' Dateien kompiliert? – SomeJavaGuy
Ihr Code funktioniert. Vielleicht haben Sie Namenskollision. – Maroun
Können Sie bitte das Anfangsbuchstabe Kapital für Ihre Klassennamen bilden. –