mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 12:35:55 +08:00
Remove unnecessary code (#4141)
This commit is contained in:
@ -58,7 +58,7 @@ public class AmicableNumber {
|
||||
countofRes +
|
||||
" Amicable_numbers.These are \n "
|
||||
);
|
||||
System.out.println(res.toString());
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,8 +52,7 @@ public class Combinations {
|
||||
// nC0 is always 1
|
||||
long solution = 1;
|
||||
for (int i = 0; i < k; i++) {
|
||||
long next = (n - i) * solution / (i + 1);
|
||||
solution = next;
|
||||
solution = (n - i) * solution / (i + 1);
|
||||
}
|
||||
return solution;
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ public class DistanceFormula {
|
||||
) {
|
||||
double dX = Math.pow(x2 - x1, 2);
|
||||
double dY = Math.pow(y2 - x1, 2);
|
||||
double d = Math.sqrt(dX + dY);
|
||||
return d;
|
||||
return Math.sqrt(dX + dY);
|
||||
}
|
||||
|
||||
public static double manhattanDistance(
|
||||
@ -20,8 +19,7 @@ public class DistanceFormula {
|
||||
double x2,
|
||||
double y2
|
||||
) {
|
||||
double d = Math.abs(x1 - x2) + Math.abs(y1 - y2);
|
||||
return d;
|
||||
return Math.abs(x1 - x2) + Math.abs(y1 - y2);
|
||||
}
|
||||
|
||||
public static int hammingDistance(int[] b1, int[] b2) {
|
||||
|
@ -26,22 +26,14 @@ public class EulerMethod {
|
||||
BiFunction<Double, Double, Double> exampleEquation1 = (x, y) -> x;
|
||||
ArrayList<double[]> points1 = eulerFull(0, 4, 0.1, 0, exampleEquation1);
|
||||
assert points1.get(points1.size() - 1)[1] == 7.800000000000003;
|
||||
points1.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points1.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
|
||||
// example from https://en.wikipedia.org/wiki/Euler_method
|
||||
System.out.println("\n\nexample 2:");
|
||||
BiFunction<Double, Double, Double> exampleEquation2 = (x, y) -> y;
|
||||
ArrayList<double[]> points2 = eulerFull(0, 4, 0.1, 1, exampleEquation2);
|
||||
assert points2.get(points2.size() - 1)[1] == 45.25925556817596;
|
||||
points2.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points2.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
|
||||
// example from https://www.geeksforgeeks.org/euler-method-solving-differential-equation/
|
||||
System.out.println("\n\nexample 3:");
|
||||
@ -55,11 +47,7 @@ public class EulerMethod {
|
||||
exampleEquation3
|
||||
);
|
||||
assert points3.get(points3.size() - 1)[1] == 1.1116729841674804;
|
||||
points3.forEach(point ->
|
||||
System.out.println(
|
||||
String.format("x: %1$f; y: %2$f", point[0], point[1])
|
||||
)
|
||||
);
|
||||
points3.forEach(point -> System.out.printf("x: %1$f; y: %2$f%n", point[0], point[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,11 +71,7 @@ public class EulerMethod {
|
||||
"stepSize should be greater than zero"
|
||||
);
|
||||
}
|
||||
double yNext =
|
||||
yCurrent +
|
||||
stepSize *
|
||||
differentialEquation.apply(xCurrent, yCurrent);
|
||||
return yNext;
|
||||
return yCurrent + stepSize * differentialEquation.apply(xCurrent, yCurrent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ public class FastInverseSqrt {
|
||||
i = 0x5f3759df - (i >> 1);
|
||||
x = Float.intBitsToFloat(i);
|
||||
x = x * (1.5f - xhalf * x * x);
|
||||
return x == (float) ((float) 1 / (float) Math.sqrt(number));
|
||||
return x == ((float) 1 / (float) Math.sqrt(number));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,11 +36,7 @@ public class KrishnamurthyNumber {
|
||||
}
|
||||
|
||||
//evaluating if sum of the factorials of the digits equals the number itself
|
||||
if (tmp == s) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return tmp == s;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.thealgorithms.maths;
|
||||
public class StandardScore {
|
||||
|
||||
public static double zScore(double num, double mean, double stdDev) {
|
||||
double z = (num - mean) / stdDev;
|
||||
return z;
|
||||
return (num - mean) / stdDev;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user