From 6c5a762128abe64356e5997f73d5cd2d828891da Mon Sep 17 00:00:00 2001 From: blzimme000 Date: Wed, 15 Dec 2021 15:14:25 -0600 Subject: [PATCH] Fixed difference/duplicates bug. --- .idea/runConfigurations.xml | 10 ---------- .idea/vcs.xml | 6 ++++++ src/com/company/Main.java | 17 ++++++----------- 3 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/com/company/Main.java b/src/com/company/Main.java index bf033be..e15945f 100644 --- a/src/com/company/Main.java +++ b/src/com/company/Main.java @@ -4,22 +4,17 @@ import java.util.Scanner; public class Main { - public static void main(String args[]) { + public static void main(String[] args) { Scanner scan = new Scanner(System.in); - System.out.println("Input the number:"); + 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(); - - for (int i = 1; i < (.5*a); i++){ - if (a%i == 0){ - System.out.print("" + i + ", " + (a/i) + ". Sum: " + (i + (a/i))); - //Adds difference (might not work, but not sure if that's because of bad online compiler) - if (i < a%i){ - System.out.println(". Difference: " + (i - (a/i))); - } else { - System.out.println(". Difference: " + ((a/i) - i)); + 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)); } } }