-1

I am getting an error(NZEC) while compiling the following programme. I am unable to figure out the error. Seems like I have done nothing wrong.

import java.util.Arrays;
import java.util.Scanner;

class mixture{
public static void main(String args[]) {
    Scanner x=new Scanner(System.in);
    int n;
    n=x.nextInt();
    int a[]=new int[n];

    for(int i=0;i<n;i++) {
        a[i]=x.nextInt();
    }
    Arrays.sort(a);
    System.out.println(a[0]*a[1]);  
}
}

The error I am getting is :

 Main.java:4: error: class mixture is public, should be declared in a file 
named mixture.java
public class mixture {
   ^
1 error
Stefan Winkler
  • 3,871
  • 1
  • 18
  • 35
  • 1
    You should always at least try compiling and running your code locally (not on some web site) before asking a question. Java has at least 2 decent free IDEs (IDEA Community edition and Eclipse). Note that I don't see any _compilation_ errors, so you must be getting a RuntimeException which you should specify. – DavidW May 29 '18 at 21:10
  • 1
    Possible duplicate of [Calculate Hash or Checksum for a table in SQL Server](https://stackoverflow.com/questions/1560306/calculate-hash-or-checksum-for-a-table-in-sql-server) – DanielM May 29 '18 at 21:11
  • Possible duplicate of [runtime error (NZEC) Java SPOJ](https://stackoverflow.com/questions/22160814/runtime-error-nzec-java-spoj) – ergohack May 29 '18 at 22:20

1 Answers1

0

In Java you always need to use the class name as the file name.

So if your class is called mixture, then you need to save the file under the name mixture.java. (Note that it is also convention in Java to make class names upper case, so you should call it Mixture).

Obviously, your file is named Main.java (so says your error message). If you want to keep the file name, you need to rename your class to Main instead.

(Note that if you are working online on some web site - you don't state this, but a commenter mentioned something like that - then maybe the website has the convention that you need to call your class Main and you cannot change that...)

Stefan Winkler
  • 3,871
  • 1
  • 18
  • 35