Made it into a seperate method
This commit is contained in:
parent
6c5a762128
commit
a63fe93d88
1 changed files with 7 additions and 1 deletions
|
@ -11,12 +11,18 @@ public class Main {
|
||||||
System.out.println("Input an integer to be factored:");
|
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");
|
System.out.println("Note: Must be positive. If negative, remove negative and make one factor negative");
|
||||||
double a = scan.nextDouble();
|
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++) {
|
for (int i = 1; i < (.5*a); i++) {
|
||||||
if (i <= a / i) {
|
if (i <= a / i) {
|
||||||
if (a % i == 0) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue