Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/main/java/com/thealgorithms/maths/LongDivision.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ public static int divide(int dividend, int divisor) {
for (int i = 0; i < dividendString.length(); i++) {
String partV1 = remainder + "" + dividendString.substring(lastIndex, i + 1);
long part1 = Long.parseLong(partV1);
if (part1 > newDivisor1) {
int quotient = 0;
while (part1 >= newDivisor1) {
part1 = part1 - newDivisor1;
quotient++;
}
answer.append(quotient);
} else if (part1 == newDivisor1) {
if (part1 >= newDivisor1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove it? Maybe it wasn't covered by tests? Because it seems to be inefficient but requires code.

Perhaps this could be written more efficiently, like this:

    int quotient = (int) (part1 / newDivisor1);
    part1 = part1 % newDivisor1;
    answer.append(quotient);

int quotient = 0;
while (part1 >= newDivisor1) {
part1 = part1 - newDivisor1;
Expand All @@ -58,7 +51,7 @@ public static int divide(int dividend, int divisor) {
} else if (part1 < newDivisor1) {
answer.append(0);
}
if (!(part1 == 0)) {
if (part1 != 0) {
remainder = String.valueOf(part1);
} else {
remainder = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.junit.jupiter.api.Test;

public class LongDivisionTest {
class LongDivisionTest {

// Requirement: Dividend (positive) is greater than divisor (positive), returns correct integer
// after division
Expand Down