required int found没有参数原因实际和形式参数列表的长度不同

时间:2018-04-15 19:26:19

标签: java

import java.lang.Math;
import javax.swing.JOptionPane;

public class IntegerNumber
{
        //declaring main variable used throughout the whole code

    public static void main(String[] args)
    {
        //declare variable
        int menuNumber;

        String input = JOptionPane.showInputDialog("Select What You want to do: \n1: Calculate the total of the squares of the first inputted natural numbers. \n 2: Get the mean of the first N odd natural numbers. \n 3: Determine if the inputted number is a prime number. \n 4: Return a Fibonacci number. \n 5: Exit Program.");
        menuNumber = Integer.parseInt(input);
        if (menuNumber == 1)
        {
            TotalSquares();
        }
        else if (menuNumber == 2)
        {
            OddNumberMean();
        }
        else if (menuNumber == 3)
        {
            PrimeNumber();
        }
        else if (menuNumber == 4)
        {
            FibonacciNumber();
        }
        else if (menuNumber == 5)
        {
            System.exit(0);
        }



    }

public static double TotalSquares()
    {
        int N;
        double total;
        int k;
                    String input = JOptionPane.showInputDialog("Enter a number between 1 and 20 to find the total squared numbers of");
            N = Integer.parseInt(input);

            total = 0;
            for(k=1; k<=N; k++);
                total +=(k*k);
            return total;
            System.out.println("Your total is = " + total);


    }
public static double OddNumberMean()
{
    int N;
    int i;
    String input = JOptionPane.showInputDialog("Enter a number between 1 and 50 to find the mean of the odd numbers");
    N = Integer.parseInt(input);
    double total = 0;
    for(i=0;i<=N; i++);
    { total+= 2*i +1;};
    System.out.println("The mean is = " + (total/N));
}

public static double PrimeNumber()
{
    int N;
    int g;
    String input = JOptionPane.showInputDialog("Enter a number between 2 and 200, determine whether or not the number is prime");
    N = Integer.parseInt(input);
            for (g = 2; g<N; g++)
            {
            if (N % g == 0)
                {
            System.out.println("The number is not prime");
                }
            }
            System.out.println("The number is prime");


}


public static int FibonacciNumber(int N)
{
    String input = JOptionPane.showInputDialog("Compute and return a Fibonacci number");
    N = Integer.parseInt(input);

        if (N==0)
            return 0;
        else if(N==1)
            return 1;
        else
            return FibonacciNumber(N-1) + FibonacciNumber(N-2);


}

}

我一直收到这个错误:

IntegerNumber.java:33: error: method FibonacciNumber in class
IntegerNumber cannot be applied to given types;              
FibonacciNumber();
                ^   required: int   found: no arguments   reason: actual and formal
argument lists differ in length

我无法找到解决问题的方法。任何帮助,因为我似乎无法在其他帖子上找到答案。

1 个答案:

答案 0 :(得分:0)

替换

public static int FibonacciNumber(int N)
{
    ...
    N = Integer.parseInt(input);

public static int FibonacciNumber()
{
    ...
    int N = Integer.parseInt(input);

您在没有参数的情况下调用FibonacciNumber(),而原始方法声明需要参数int N

此外,对于方法,字段和变量使用初始小写字母:fibonacciNumber, n