Error: Could not find or load main class solved

Asked

Viewed 16,499 times

2

I am training for OBI and am picking up the exercises on your website and sending to run on it too, but my code is giving error:

Error: Could not find or load main class solved

"Error: Unable to locate or load the main class fixed" and in my terminal too, why will it be?

package treinamento;

import java.util.Scanner;

/**
*
* @author mrminerin
*/
public class solucao {

public static void main (String[]args) {
    Scanner sc = new Scanner(System.in);

    int n = Integer.parseInt(sc.nextLine());
    String [] pedacos = sc.nextLine().split(" ");
    int [] pedacos2 = new int[pedacos.length];
    int pedaco = 0;
    for (int i = 0; i < pedacos.length; i++) {
        pedacos2[i] = Integer.parseInt(pedacos[i]);    
        pedaco += pedacos2[i];      
    }
    System.out.println(pedaco - n);
  }

}

1 answer

5

I did some tests with your class and I managed to run it.

You should be careful how you run your class, if you try to call it inside the training folder you will not be able to run.

 ── treinamento
    ├── solucao.class
    └── solucao.java

You need to call out the folder as follows java treinamento.solucao.

If you want to run directly inside the training folder, you can remove the package declaration at the beginning of the file, so inside the training folder you will be able to run with java solucao.

Note: Java class names are written from another form

  • 1

    Yes, I know it must be capitalized, but they ask in this way.

  • @Mrminerin in this case is "custom", the only obligation is to have the same file name

  • @Mrminerin if the answer helped you, can mark it as accepted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.