Exception in thread “main” Java.lang.NoSuchMethodE

2020-05-09 19:25发布

import java.io.*;
import java.lang.Math;
class Squr
{
  public static void main ()
  { 
   int m =10,n;
   double z = 10.4,p;
   Squr square = new Squr();
   p = (double)square.mysqrt(z);
   n = (int)square.mysqrt(m);
   System.out.println ("square root of 10 : " + n );
   System.out.println ("square root of 10.4 : "+ p );  
  }
    double mysqrt (double y)
   {
     return Math.sqrt(y);
   }
   int mysqrt (int x)
   {
     return (int)Math.sqrt(x);
   }

}

This code is compiling but when we try to execute it it giving " Exception in thread "main" Java.lang.NoSuchMethodError: main "

标签: java
6条回答
再贱就再见
2楼-- · 2020-05-09 19:35

Your main() method should be like that

public static void main(String args[])

or

public static void main(String[] args)

or

public static void main(String... args)
查看更多
beautiful°
3楼-- · 2020-05-09 19:38

The main() function should be declared like this

public static void main(String[] args)
查看更多
乱世女痞
4楼-- · 2020-05-09 19:38

Java is a strong type language. You must declare the method in a given way. The right way to define the main() method is:

public static void main (String[] args)
查看更多
我命由我不由天
5楼-- · 2020-05-09 19:41

The correct method signature for the main method in Java is:

public static void main(String args[])

Simply add the missing arguments in you method declaration and it should work.

查看更多
够拽才男人
6楼-- · 2020-05-09 19:42

It looks like you've not defined your main method with the correct signature. It should be:

public class Squr
{
  public static void main(String[] args)
查看更多
我命由我不由天
7楼-- · 2020-05-09 19:52

Try that:

public static void main(String [ ] args)
查看更多
登录 后发表回答