-1

I have compiled this code but it says "could not find or load main class test3"
test3 is the name of file.
The code is:

class TowDArray {
public static void main(String args[]) {
    int twoD[][]=new int[4][5];
    int i,j,k=0;
    for (i=0;i<4;i++)
        for (j=0;j<5;j++) {
            twoD[i][j]=k;
            k++;
        }
    for (i=0;i<4;i++){
        for (j=0;j<5;j++)
            System.out.print(twoD[i][j]+" ");
        System.out.println();
    }
}

}

Can you please tell me what the problem is

  • 3
    the problem is that the name of the class is `TowDArray` and not `test3` – dumbPotato21 May 14 '17 at 14:54
  • 2
    For Java, the public class name and file name should be same. You should save this file as `TowDArray.java` – Master Po May 14 '17 at 14:54
  • Possible duplicate of [What does "Could not find or load main class" mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – rghome May 14 '17 at 15:07
  • Type the error message into Google and you will find the answer. Isn't that easier than creating a question on SO? – rghome May 14 '17 at 15:08
  • Are you sure that a better name isn't `TwoDArray`? – Lew Bloch May 14 '17 at 15:27

2 Answers2

2

First make the class public

public class TowDArray

Rename the file as

TowDArray.java

And try running it by

javac TowDArray.java
java TowDArray
Janith Jeewantha
  • 185
  • 2
  • 12
0

Do

java TowDArray

instead of

java test3
dumbPotato21
  • 5,669
  • 5
  • 21
  • 34