i don know how to calling the method

1.Write a static boolean method – a method that returns a boolean – that takes an int parameter and converts the integers 0 and 1 into false and true respectively. Include a main() method to test the boolean method.

my code:

public class Assignment2task1
{
   public static boolean isPrime (int N)

   {

      if (N <= 0)return false;
      System.out.println ("you entered 0 which evaluates to false");
      for (int i = 1; i<=N/i; i++)
      if (N>=1)return true;
      System.out.println ("you entered 1 which evaluates to true");

      return true;  

   }
}

import java.util.Scanner;

public class TestBoolean
{

    public static void main(String[] args) 
    {
        Scanner input = new Scanner(System.in);
        int  N;
        boolean Evaluate;


        System.out.println("enter the first number :");
        N = input.nextInt();

        Evaluate = Assignment2task1.boolean isPrime (N);
    }

}

You need to call the isPrime() method by just using the class name. Since its a static method, you need to use the class name to call it. Also, you should not the return type along with it or while calling any other method.

Evaluate = Assignment2task1.isPrime(N); // ClassName.staticMethod();
链接地址: http://www.djcxy.com/p/15204.html

上一篇: 最快的整数平方根[最少量的指令]

下一篇: 我不知道如何调用该方法