# How do I find the factors of primes and then add them?

Need to find all factors of a number, then add them up, check against the number and if so, print it and the numbers.

Tried a bunch of stuff, still trying more things, please check my code

``````import java.util.Scanner;
public class PrimeCheck {

public static void main(String args[])
{
// loop 20k
int x = 0;
while(x < 20)
{

long number;
long count = 0;
int numberStore = x;
number = x;

//   Scanner scan = new Scanner(System.in);
//  System.out.println("Enter a number ::");

numberStore += number;

// Check for factors and cycle through up to number
// long incase high number

for(long i = 2; i< number; i++)
{

// if remainder is 0 - can be divided by that #
while(number%i == 0)
{

count += i;
//print factors
// System.out.println(i+" ");
// divide out num to primes
number = number/i;

}
}
// print final #
if(number >2 && number == count)
{
System.out.println(number);
}

count += number;

// Print  ~~ + the total store and added primes

System.out.println(" ~~ ");
System.out.println(count);
System.out.println(numberStore);
System.out.println(" ~~ ");
// If store is same as counter, it works
if(numberStore == count )
{
System.out.println(count + " This works!");
}
x++;
}

}
}
``````

Actual results should show 6 and print that,and it's primes, instead, the counter only is 3 when it should be 6