-1

I want to execute this class from console by "java". I have no problems with compilation, but what do I have to write to call this class? If I don't specify the package, no problems.

package myfirstpackage;
// import myfirstpackage.*;
class MyFirstClass{
    public static void main(String[] args) {
        // MySecondClass msc = new MySecondClass(); 
//      for( int i = 1 , j , size = Integer.parseInt( args[ 0 ] ) ; i <= size ; i++ ){
//          for( j = 1 ; j <= size ; j++ ){
//              msc.setFirst( i );
//              msc.setSecond( j );
//              System.out.printf( "%3d " , msc.multiplyFirtsAndSecond() );
//          }       
//          System.out.println();           
//      }
        System.out.println("A");
    }
}
0

1 Answer 1

-1

First compilation :

> javac classname.java

And then you can run it

> java classname

Hope it helps

2
  • java MyFirstClass Error: Could not find or load main class MyFirstClass Sep 20, 2017 at 16:10
  • If you type dir can you see the MyFirstClass file ? Because otherwise you should go back in the main directory where it will be compilated. Sep 20, 2017 at 16:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.