-1

I have trouble with NetBeans quite frequently. Earlier I was able to run this program no problem, but now, it tells me this after running it

"Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -cannot find symbol symbol: class Loop1 location: class hw7 at hw7.main(hw7.java:72)"

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();
}

}

ToonLink
  • 1
  • 1
  • 2
  • 4

2 Answers2

2

You're not instantiating the class correctly. Since it's name is forLoops, you need to do something like:

forLoops myL1 = new forLoops();
myL1.forLoop1();
forLoops myL2 = new forLoops();
myL2.forLoop2();
forLoops myL3 = new forLoops();
myL3.forLoop3();

Unrelated to the question, note that classes in Java start with a capital letter, by convention.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
2

This is line 72: Loop1 myL1 = new Loop1();

You are using a class named Loop1, but you have not defined it.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151