package factors;
import java.util.Scanner;
public class Factors {
private int data;
private boolean [] factors;
private int [] arr;
private int x;
Factors(int d){
data = d;
int m = 0;
factors = new boolean[data];
int n = 0;
for(int i=1; i<=data; i++){
if(data % i==0){
factors[n] = true;
n++;
m++;
}
else{
factors[n] = false;
n++;
}
}
for(int i=0; i<factors.length; i++){
System.out.printf("%b ", factors[i]);
}
x=0;
arr = new int[m];
}
void populate(){
int n = 1;
int f = 0;
while(n<=data){
if(data %n ==0){
arr[f] = n;
factors[f] = true;
f++;
}
n++;
}
}
void display(){
System.out.printf("\nFactors of %d are: ", data);
int sum = 0;
for(int i=0; i<arr.length; i++){
System.out.printf("%d, ",arr[i]);
}
for(int i=0; i<arr.length-1; i++){
sum +=arr[i];
}
if(sum==data){
System.out.printf("\n%d, is a perfect number\n", data);
}
else{
System.out.printf("\n%d, is not a perfect number\n", data);
}
}
void common_unique_factors(Factors f){
int first = f.arr.length;
int x = f.arr[0];
int second = arr.length;
System.out.printf("\nFirst array length: %d", first);
System.out.printf("\nSecond array length: %d\n", second);
int max = first;
int min = second;
if(second>first){
max = second;
min = first;
}
for(int i=0; i<max; i++){
if(i==min || i==max){
break;
}
int t1= arr[i];
int t2 = f.arr[i];
if(t1==t2){
}
}
}
public static void main(String[] args) {
Factors f1 = new Factors(28);
f1.populate();
f1.display();
Factors f2 = new Factors(42);
f2.populate();
f2.display();
f1.common_unique_factors(f2);
}
}
Comments
Leave a comment