PR1/TestProgs/PerfectNumber.java

55 lines
687 B
Java

import java.lang.Math;
public class PerfectNumber{
public static void main (String[] args){
long a = 1; //Ausgabe
long zw1 = 0; //Zwischenrechnung
long zw2 = 0; //Zwischenrechnung
int i = 2; //Schleife
int j = 1; //Schleife
System.out.println("5 Perfect Numeros.");
while (i < 14){
if (i == 2 || i == 3 || i == 5 || i == 7 || i == 13 ){
System.out.println();
zw1 = (long) Math.pow(2,(i-1));
zw2 = (long) Math.pow(2,i);
a = zw1 * (zw2-1);
System.out.print( a + " = ");
for (j = 1; j < a/2+1; j++){
if (a % j == 0){
if(j == a/2){
System.out.print(j);
}
else {
System.out.print(j + " + ");
}
}
}
}
i ++;
}
}
}