Skip to content

Commit 0f03b13

Browse files
rheerrheer
authored andcommitted
Code commit
1 parent c06a4c7 commit 0f03b13

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.java.heera;
2+
public class PerfectNumber {
3+
//Perfect Number--> 6-> 1,2,3
4+
//28--> 1,2,4,7,14
5+
public static void main(String[] args) {
6+
int n=6;
7+
boolean b=isPerfect(n);
8+
9+
if(b) {
10+
System.out.println("Its is a Perfect Number");
11+
12+
}
13+
else
14+
System.out.println("It is not a Perfect Number");
15+
16+
}
17+
18+
public static boolean isPerfect(int n) {
19+
20+
int sum=0;
21+
for(int i=1;i<n;i++) //for(int i=1;i<n/2;i++) we dont have to go to the last number
22+
//till half number is only needed to check the factors
23+
{
24+
if(n%i==0)
25+
//sum=sum+i; --> sum=sum+i;
26+
sum+=i;
27+
28+
}
29+
System.out.println("Sum:"+sum);
30+
if(n==sum)
31+
return true;
32+
33+
return false;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)