Made it into a seperate method

This commit is contained in:
blzimme000 2021-12-15 15:22:26 -06:00
parent 6c5a762128
commit a63fe93d88

View file

@ -11,12 +11,18 @@ public class Main {
System.out.println("Input an integer to be factored:");
System.out.println("Note: Must be positive. If negative, remove negative and make one factor negative");
double a = scan.nextDouble();
System.out.println(factor(a));
}
public static String factor(double a){
String thingtoreturn = "";
for (int i = 1; i < (.5*a); i++) {
if (i <= a / i) {
if (a % i == 0) {
System.out.println("" + i + ", " + (a / i) + ". Sum: " + (i + (a / i)) + ". Difference: " + ((a / i) - i));
thingtoreturn += "" + i + ", " + (a / i) + ". Sum: " + (i + (a / i)) + ". Difference: " + ((a / i) - i) + "\n";
}
}
}
return thingtoreturn;
}
}