私は、ネストされたループメソッドをmain関数に呼び出そうとしています。私は2つのエラーcannot be resolved or is not a field
とthe method patternA() is undefined for the type classNested
を得ました。私はそれが本当に一般的なエラーだと知っていますが、私はまだそれを解決する方法を見つけることができませんでした。メイン関数の呼び出し方法
ここに私のメインクラスが
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"
}
}
だし、ここに方法
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();
}
}
}
第一のエラーです:
Description Resource Path Location Type
n cannot be resolved or is not a field nestedLoops.java /chapter1/src/nomerTuhuh line 14 Java Problem
第二のエラー:
Description Resource Path Location Type
The method patternA() is undefined for the type classNested nestedLoops.java /chapter1/src/nomerTuhuh line 16 Java Problem
誰かが間違っていることを教えてもらえますか?ありがとうございました。
'.java'ファイルをどのようにコンパイルしましたか? – SomeJavaGuy
コードが動作します。多分あなたは衝突の命名をしているかもしれません。 – Maroun
あなたのクラス名には、最初の大文字を使用してください。 –