Computer Science, asked by MayankVijayKumar, 6 months ago

function method program in java

function method in java programming​

Answers

Answered by Anonymous
5

Answer:

❮ Previous Next ❯ A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions.

Answered by sahunix
0

/*to check whether a number is Perfect number or not*/

import java.util.*;

class Perfect

{

   public static void main(String args[])

   {

       Scanner sc = new Scanner(System.in);

       int a,n,s=0;

       System.out.println("Enter a number");

       n = sc.nextInt();

       for (a=1;a<n;a++)

       {

           if (n%a==0)

               s = s+a;

       }

       if (s==n)

           System.out.println("Perfect number");

       else

           System.out.println("Not Perfect number");

   }

}

Similar questions