function method program in java
function method in java programming
Answers
Answered by
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
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
Math,
3 months ago
Science,
3 months ago
English,
6 months ago
Political Science,
6 months ago
Art,
1 year ago