我经常在使用 NetBeans 时遇到问题。早些时候我能够运行这个程序没问题,但现在,它在运行后告诉我这个
“线程“主”java.lang.RuntimeException 中的异常:无法编译的源代码 - 找不到符号符号:类 Loop1 位置:hw7.main(hw7.java:72) 处的类 hw7”
import java.util.Scanner;
class forLoops {
void forLoop1(){
Scanner in = new Scanner(System.in);
int cnt = 2;
System.out.print("Enter n:");
int n = in.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++){
if (i == 1)
System.out.print(1);
else if (i > 1) {
System.out.printf("%3d", cnt);
cnt++;
}
}
System.out.println();
}
}
void forLoop2(){
Scanner in = new Scanner(System.in);
System.out.print("Enter n:");
int n = in.nextInt();
for (int i = 1; i < n+1; i++) {
int sum = 0;
for (int j = 0; j < i; j++){
System.out.printf("%3d", i+sum);
sum = sum + n-(j+1);
}
System.out.println();
}
}
void forLoop3(){
Scanner in = new Scanner(System.in);
System.out.print("Enter n:");
int n = in.nextInt();
int x = 1;
for (int i = 1; i < n+1; i++) {
int sum = 0;
for (int j = 0; j < i; j++){
System.out.printf("%3d", i+sum);
sum = sum + n-(j+1);
}
System.out.println();
}
}
}
public class hw7 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
forLoops myL1 = new forLoops();
myL1.forLoop1();
forLoops myL2 = new forLoops();
myL2.forLoop2();
Loops myL3 = new forLoops();
myL3.forLoop3();
}
}