mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-08-01 18:49:39 +08:00
Add automatic linter (#4214)
This commit is contained in:
@ -21,8 +21,7 @@ public record ADTFraction(int numerator, int denominator) {
|
||||
* @return A new {@code ADTFraction} containing the result of the operation
|
||||
*/
|
||||
public ADTFraction plus(ADTFraction fraction) {
|
||||
var numerator
|
||||
= this.denominator * fraction.numerator + this.numerator * fraction.denominator;
|
||||
var numerator = this.denominator * fraction.numerator + this.numerator * fraction.denominator;
|
||||
var denominator = this.denominator * fraction.denominator;
|
||||
return new ADTFraction(numerator, denominator);
|
||||
}
|
||||
|
@ -17,10 +17,7 @@ public class AbsoluteMin {
|
||||
|
||||
var absMinWrapper = new Object() { int value = numbers[0]; };
|
||||
|
||||
Arrays.stream(numbers)
|
||||
.skip(1)
|
||||
.filter(number -> Math.abs(number) < Math.abs(absMinWrapper.value))
|
||||
.forEach(number -> absMinWrapper.value = number);
|
||||
Arrays.stream(numbers).skip(1).filter(number -> Math.abs(number) < Math.abs(absMinWrapper.value)).forEach(number -> absMinWrapper.value = number);
|
||||
|
||||
return absMinWrapper.value;
|
||||
}
|
||||
|
@ -20,10 +20,7 @@ public class AliquotSum {
|
||||
public static int getAliquotValue(int number) {
|
||||
var sumWrapper = new Object() { int value = 0; };
|
||||
|
||||
IntStream.iterate(1, i -> ++i)
|
||||
.limit(number / 2)
|
||||
.filter(i -> number % i == 0)
|
||||
.forEach(i -> sumWrapper.value += i);
|
||||
IntStream.iterate(1, i -> ++i).limit(number / 2).filter(i -> number % i == 0).forEach(i -> sumWrapper.value += i);
|
||||
|
||||
return sumWrapper.value;
|
||||
}
|
||||
|
@ -47,9 +47,7 @@ public class AmicableNumber {
|
||||
}
|
||||
}
|
||||
}
|
||||
res.insert(0,
|
||||
"Int Range of " + startValue + " till " + stopValue + " there are " + countofRes
|
||||
+ " Amicable_numbers.These are \n ");
|
||||
res.insert(0, "Int Range of " + startValue + " till " + stopValue + " there are " + countofRes + " Amicable_numbers.These are \n ");
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
@ -61,8 +59,7 @@ public class AmicableNumber {
|
||||
* otherwise false
|
||||
*/
|
||||
static boolean isAmicableNumber(int numberOne, int numberTwo) {
|
||||
return ((recursiveCalcOfDividerSum(numberOne, numberOne) == numberTwo
|
||||
&& numberOne == recursiveCalcOfDividerSum(numberTwo, numberTwo)));
|
||||
return ((recursiveCalcOfDividerSum(numberOne, numberOne) == numberTwo && numberOne == recursiveCalcOfDividerSum(numberTwo, numberTwo)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,8 +135,7 @@ public class Area {
|
||||
* @param height height of trapezium
|
||||
* @return area of given trapezium
|
||||
*/
|
||||
public static double surfaceAreaTrapezium(
|
||||
final double base1, final double base2, final double height) {
|
||||
public static double surfaceAreaTrapezium(final double base1, final double base2, final double height) {
|
||||
if (base1 <= 0) {
|
||||
throw new IllegalArgumentException(POSITIVE_BASE + 1);
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ public class AutomorphicNumber {
|
||||
numberOfdigits++; // Calculating number of digits in n
|
||||
t /= 10;
|
||||
}
|
||||
long lastDigits
|
||||
= square % (long) Math.pow(10, numberOfdigits); // Extracting last Digits of square
|
||||
long lastDigits = square % (long) Math.pow(10, numberOfdigits); // Extracting last Digits of square
|
||||
return n == lastDigits;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ public class BinomialCoefficient {
|
||||
}
|
||||
|
||||
// Recursive Call
|
||||
return (binomialCoefficient(totalObjects - 1, numberOfObjects - 1)
|
||||
+ binomialCoefficient(totalObjects - 1, numberOfObjects));
|
||||
return (binomialCoefficient(totalObjects - 1, numberOfObjects - 1) + binomialCoefficient(totalObjects - 1, numberOfObjects));
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,8 @@ public class CircularConvolutionFFT {
|
||||
* @param b The other signal.
|
||||
* @return The convolved signal.
|
||||
*/
|
||||
public static ArrayList<FFT.Complex> fftCircularConvolution(
|
||||
ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b) {
|
||||
int convolvedSize = Math.max(
|
||||
a.size(), b.size()); // The two signals must have the same size equal to the bigger one
|
||||
public static ArrayList<FFT.Complex> fftCircularConvolution(ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b) {
|
||||
int convolvedSize = Math.max(a.size(), b.size()); // The two signals must have the same size equal to the bigger one
|
||||
padding(a, convolvedSize); // Zero padding the smaller signal
|
||||
padding(b, convolvedSize);
|
||||
|
||||
|
@ -42,8 +42,7 @@ public class ConvolutionFFT {
|
||||
* @param b The other signal.
|
||||
* @return The convolved signal.
|
||||
*/
|
||||
public static ArrayList<FFT.Complex> convolutionFFT(
|
||||
ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b) {
|
||||
public static ArrayList<FFT.Complex> convolutionFFT(ArrayList<FFT.Complex> a, ArrayList<FFT.Complex> b) {
|
||||
int convolvedSize = a.size() + b.size() - 1; // The size of the convolved signal
|
||||
padding(a, convolvedSize); // Zero padding both signals
|
||||
padding(b, convolvedSize);
|
||||
@ -58,9 +57,8 @@ public class ConvolutionFFT {
|
||||
convolved.add(a.get(i).multiply(b.get(i))); // FFT(a)*FFT(b)
|
||||
}
|
||||
FFT.fft(convolved, true); // IFFT
|
||||
convolved.subList(convolvedSize, convolved.size())
|
||||
.clear(); // Remove the remaining zeros after the convolvedSize. These extra zeros came
|
||||
// from
|
||||
convolved.subList(convolvedSize, convolved.size()).clear(); // Remove the remaining zeros after the convolvedSize. These extra zeros came
|
||||
// from
|
||||
// paddingPowerOfTwo() method inside the fft() method.
|
||||
|
||||
return convolved;
|
||||
|
@ -53,8 +53,7 @@ public class EulerMethod {
|
||||
* @param differentialEquation The differential equation to be solved.
|
||||
* @return The next y-value.
|
||||
*/
|
||||
public static double eulerStep(double xCurrent, double stepSize, double yCurrent,
|
||||
BiFunction<Double, Double, Double> differentialEquation) {
|
||||
public static double eulerStep(double xCurrent, double stepSize, double yCurrent, BiFunction<Double, Double, Double> differentialEquation) {
|
||||
if (stepSize <= 0) {
|
||||
throw new IllegalArgumentException("stepSize should be greater than zero");
|
||||
}
|
||||
@ -73,8 +72,7 @@ public class EulerMethod {
|
||||
* @return The points constituting the solution of the differential
|
||||
* equation.
|
||||
*/
|
||||
public static ArrayList<double[]> eulerFull(double xStart, double xEnd, double stepSize,
|
||||
double yStart, BiFunction<Double, Double, Double> differentialEquation) {
|
||||
public static ArrayList<double[]> eulerFull(double xStart, double xEnd, double stepSize, double yStart, BiFunction<Double, Double, Double> differentialEquation) {
|
||||
if (xStart >= xEnd) {
|
||||
throw new IllegalArgumentException("xEnd should be greater than xStart");
|
||||
}
|
||||
|
@ -25,24 +25,15 @@ public class FibonacciJavaStreams {
|
||||
return Optional.of(BigDecimal.ONE);
|
||||
}
|
||||
|
||||
final List<BigDecimal> results
|
||||
= Stream
|
||||
.iterate(
|
||||
index, x -> x.compareTo(BigDecimal.ZERO) > 0, x -> x.subtract(BigDecimal.ONE))
|
||||
.reduce(List.of(),
|
||||
(list, current)
|
||||
-> list.isEmpty() || list.size() < 2
|
||||
? List.of(BigDecimal.ZERO, BigDecimal.ONE)
|
||||
: List.of(list.get(1), list.get(0).add(list.get(1))),
|
||||
(list1, list2) -> list1);
|
||||
final List<BigDecimal> results = Stream.iterate(index, x -> x.compareTo(BigDecimal.ZERO) > 0, x -> x.subtract(BigDecimal.ONE))
|
||||
.reduce(List.of(), (list, current) -> list.isEmpty() || list.size() < 2 ? List.of(BigDecimal.ZERO, BigDecimal.ONE) : List.of(list.get(1), list.get(0).add(list.get(1))), (list1, list2) -> list1);
|
||||
|
||||
return results.isEmpty() ? Optional.empty() : Optional.of(results.get(results.size() - 1));
|
||||
}
|
||||
|
||||
public static void assertThat(final Object actual, final Object expected) {
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
throw new AssertionError(
|
||||
String.format("expected=%s but was actual=%s", expected, actual));
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s", expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,8 +95,7 @@ public class FibonacciJavaStreams {
|
||||
{
|
||||
final Optional<BigDecimal> result = calculate(new BigDecimal(200));
|
||||
assertThat(result.isPresent(), true);
|
||||
result.ifPresent(value
|
||||
-> assertThat(value, new BigDecimal("280571172992510140037611932413038677189525")));
|
||||
result.ifPresent(value -> assertThat(value, new BigDecimal("280571172992510140037611932413038677189525")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,10 @@ public class KaprekarNumbers {
|
||||
BigInteger leftDigits1 = BigInteger.ZERO;
|
||||
BigInteger leftDigits2;
|
||||
if (numberSquared.toString().contains("0")) {
|
||||
leftDigits1 = new BigInteger(
|
||||
numberSquared.toString().substring(0, numberSquared.toString().indexOf("0")));
|
||||
leftDigits1 = new BigInteger(numberSquared.toString().substring(0, numberSquared.toString().indexOf("0")));
|
||||
}
|
||||
leftDigits2 = new BigInteger(numberSquared.toString().substring(
|
||||
0, (numberSquared.toString().length() - number.length())));
|
||||
BigInteger rightDigits = new BigInteger(numberSquared.toString().substring(
|
||||
numberSquared.toString().length() - number.length()));
|
||||
leftDigits2 = new BigInteger(numberSquared.toString().substring(0, (numberSquared.toString().length() - number.length())));
|
||||
BigInteger rightDigits = new BigInteger(numberSquared.toString().substring(numberSquared.toString().length() - number.length()));
|
||||
String x = leftDigits1.add(rightDigits).toString();
|
||||
String y = leftDigits2.add(rightDigits).toString();
|
||||
return (number.equals(x)) || (number.equals(y));
|
||||
|
@ -27,8 +27,7 @@ public final class LinearDiophantineEquationsSolver {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private static GcdSolutionWrapper gcd(
|
||||
final int a, final int b, final GcdSolutionWrapper previous) {
|
||||
private static GcdSolutionWrapper gcd(final int a, final int b, final GcdSolutionWrapper previous) {
|
||||
if (b == 0) {
|
||||
return new GcdSolutionWrapper(a, new Solution(1, 0));
|
||||
}
|
||||
@ -36,18 +35,15 @@ public final class LinearDiophantineEquationsSolver {
|
||||
final var stubWrapper = new GcdSolutionWrapper(0, new Solution(0, 0));
|
||||
final var next = /* recursive call */ gcd(b, a % b, stubWrapper);
|
||||
previous.getSolution().setX(next.getSolution().getY());
|
||||
previous.getSolution().setY(
|
||||
next.getSolution().getX() - (a / b) * (next.getSolution().getY()));
|
||||
previous.getSolution().setY(next.getSolution().getX() - (a / b) * (next.getSolution().getY()));
|
||||
previous.setGcd(next.getGcd());
|
||||
return new GcdSolutionWrapper(next.getGcd(), previous.getSolution());
|
||||
}
|
||||
|
||||
public static final class Solution {
|
||||
|
||||
public static final Solution NO_SOLUTION
|
||||
= new Solution(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
public static final Solution INFINITE_SOLUTIONS
|
||||
= new Solution(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
public static final Solution NO_SOLUTION = new Solution(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
public static final Solution INFINITE_SOLUTIONS = new Solution(Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
|
@ -17,19 +17,15 @@ public class MatrixUtil {
|
||||
return matrix != null && matrix.length > 0 && matrix[0].length > 0;
|
||||
}
|
||||
|
||||
public static boolean hasEqualSizes(
|
||||
final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
return (isValid(matrix1) && isValid(matrix2) && matrix1.length == matrix2.length
|
||||
&& matrix1[0].length == matrix2[0].length);
|
||||
public static boolean hasEqualSizes(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
return (isValid(matrix1) && isValid(matrix2) && matrix1.length == matrix2.length && matrix1[0].length == matrix2[0].length);
|
||||
}
|
||||
|
||||
public static boolean canMultiply(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
return (isValid(matrix1) && isValid(matrix2) && matrix1[0].length == matrix2.length);
|
||||
}
|
||||
|
||||
public static Optional<BigDecimal[][]> operate(final BigDecimal[][] matrix1,
|
||||
final BigDecimal[][] matrix2,
|
||||
final BiFunction<BigDecimal, BigDecimal, BigDecimal> operation) {
|
||||
public static Optional<BigDecimal[][]> operate(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2, final BiFunction<BigDecimal, BigDecimal, BigDecimal> operation) {
|
||||
if (!hasEqualSizes(matrix1, matrix2)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@ -39,29 +35,25 @@ public class MatrixUtil {
|
||||
|
||||
final BigDecimal[][] result = new BigDecimal[rowSize][columnSize];
|
||||
|
||||
IntStream.range(0, rowSize)
|
||||
.forEach(rowIndex -> IntStream.range(0, columnSize).forEach(columnIndex -> {
|
||||
final BigDecimal value1 = matrix1[rowIndex][columnIndex];
|
||||
final BigDecimal value2 = matrix2[rowIndex][columnIndex];
|
||||
IntStream.range(0, rowSize).forEach(rowIndex -> IntStream.range(0, columnSize).forEach(columnIndex -> {
|
||||
final BigDecimal value1 = matrix1[rowIndex][columnIndex];
|
||||
final BigDecimal value2 = matrix2[rowIndex][columnIndex];
|
||||
|
||||
result[rowIndex][columnIndex] = operation.apply(value1, value2);
|
||||
}));
|
||||
result[rowIndex][columnIndex] = operation.apply(value1, value2);
|
||||
}));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
public static Optional<BigDecimal[][]> add(
|
||||
final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
public static Optional<BigDecimal[][]> add(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
return operate(matrix1, matrix2, BigDecimal::add);
|
||||
}
|
||||
|
||||
public static Optional<BigDecimal[][]> subtract(
|
||||
final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
public static Optional<BigDecimal[][]> subtract(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
return operate(matrix1, matrix2, BigDecimal::subtract);
|
||||
}
|
||||
|
||||
public static Optional<BigDecimal[][]> multiply(
|
||||
final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
public static Optional<BigDecimal[][]> multiply(final BigDecimal[][] matrix1, final BigDecimal[][] matrix2) {
|
||||
if (!canMultiply(matrix1, matrix2)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@ -77,23 +69,21 @@ public class MatrixUtil {
|
||||
.forEach(rowIndex
|
||||
-> IntStream.range(0, matrix2ColumnSize)
|
||||
.forEach(columnIndex
|
||||
-> result[rowIndex][columnIndex]
|
||||
= IntStream.range(0, size)
|
||||
.mapToObj(index -> {
|
||||
final BigDecimal value1 = matrix1[rowIndex][index];
|
||||
final BigDecimal value2 = matrix2[index][columnIndex];
|
||||
-> result[rowIndex][columnIndex] = IntStream.range(0, size)
|
||||
.mapToObj(index -> {
|
||||
final BigDecimal value1 = matrix1[rowIndex][index];
|
||||
final BigDecimal value2 = matrix2[index][columnIndex];
|
||||
|
||||
return value1.multiply(value2);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)));
|
||||
return value1.multiply(value2);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
public static void assertThat(final BigDecimal[][] actual, final BigDecimal[][] expected) {
|
||||
if (!Objects.deepEquals(actual, expected)) {
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s",
|
||||
Arrays.deepToString(expected), Arrays.deepToString(actual)));
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s", Arrays.deepToString(expected), Arrays.deepToString(actual)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,9 +99,7 @@ public class MatrixUtil {
|
||||
{new BigDecimal(2), new BigDecimal(0)},
|
||||
};
|
||||
|
||||
final BigDecimal[][] actual
|
||||
= add(matrix1, matrix2)
|
||||
.orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
final BigDecimal[][] actual = add(matrix1, matrix2).orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
|
||||
final BigDecimal[][] expected = {
|
||||
{new BigDecimal(4), new BigDecimal(5)},
|
||||
@ -132,9 +120,7 @@ public class MatrixUtil {
|
||||
{new BigDecimal(-2), new BigDecimal(-3)},
|
||||
};
|
||||
|
||||
final BigDecimal[][] actual
|
||||
= subtract(matrix1, matrix2)
|
||||
.orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
final BigDecimal[][] actual = subtract(matrix1, matrix2).orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
|
||||
final BigDecimal[][] expected = {
|
||||
{new BigDecimal(-1), new BigDecimal(4)},
|
||||
@ -157,9 +143,7 @@ public class MatrixUtil {
|
||||
{new BigDecimal(5), new BigDecimal(6)},
|
||||
};
|
||||
|
||||
final BigDecimal[][] actual
|
||||
= multiply(matrix1, matrix2)
|
||||
.orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
final BigDecimal[][] actual = multiply(matrix1, matrix2).orElseThrow(() -> new AssertionError("Could not compute matrix!"));
|
||||
|
||||
final BigDecimal[][] expected = {
|
||||
{new BigDecimal(22), new BigDecimal(28)},
|
||||
|
@ -15,7 +15,6 @@ public class Median {
|
||||
public static double median(int[] values) {
|
||||
Arrays.sort(values);
|
||||
int length = values.length;
|
||||
return length % 2 == 0 ? (values[length / 2] + values[length / 2 - 1]) / 2.0
|
||||
: values[length / 2];
|
||||
return length % 2 == 0 ? (values[length / 2] + values[length / 2 - 1]) / 2.0 : values[length / 2];
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ public class NonRepeatingElement {
|
||||
}
|
||||
int[] arr = new int[n];
|
||||
|
||||
System.out.println(
|
||||
"Enter " + n + " elements in the array. NOTE: Only 2 elements should not repeat");
|
||||
System.out.println("Enter " + n + " elements in the array. NOTE: Only 2 elements should not repeat");
|
||||
for (i = 0; i < n; i++) {
|
||||
arr[i] = sc.nextInt();
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ public class Perimeter {
|
||||
* @param sides for length of remaining sides
|
||||
* @return Perimeter of given trapezoid.
|
||||
*/
|
||||
public static float perimeterIrregularPolygon(
|
||||
float side1, float side2, float side3, float... sides) {
|
||||
public static float perimeterIrregularPolygon(float side1, float side2, float side3, float... sides) {
|
||||
float perimeter = side1 + side2 + side3;
|
||||
for (float side : sides) {
|
||||
perimeter += side;
|
||||
|
@ -63,11 +63,9 @@ public class RomanNumeralUtil {
|
||||
|
||||
public static String generate(int number) {
|
||||
if (number < MIN_VALUE || number > MAX_VALUE) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("The number must be in the range [%d, %d]", MIN_VALUE, MAX_VALUE));
|
||||
throw new IllegalArgumentException(String.format("The number must be in the range [%d, %d]", MIN_VALUE, MAX_VALUE));
|
||||
}
|
||||
|
||||
return (RN_M[number / 1000] + RN_C[number % 1000 / 100] + RN_X[number % 100 / 10]
|
||||
+ RN_I[number % 10]);
|
||||
return (RN_M[number / 1000] + RN_C[number % 1000 / 100] + RN_X[number % 100 / 10] + RN_I[number % 10]);
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,8 @@ public class SquareRootWithNewtonRaphsonMethod {
|
||||
double x = n; // initially taking a guess that x = n.
|
||||
double root = 0.5 * (x + n / x); // applying Newton-Raphson Method.
|
||||
|
||||
while (
|
||||
Math.abs(root - x) > 0.0000001) { // root - x = error and error < 0.0000001, 0.0000001
|
||||
// is the precision value taken over here.
|
||||
while (Math.abs(root - x) > 0.0000001) { // root - x = error and error < 0.0000001, 0.0000001
|
||||
// is the precision value taken over here.
|
||||
x = root; // decreasing the value of x to root, i.e. decreasing the guess.
|
||||
root = 0.5 * (x + n / x);
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ package com.thealgorithms.maths;
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
assert sumOfDigits(-123) == 6 && sumOfDigitsRecursion(-123) == 6
|
||||
&& sumOfDigitsFast(-123) == 6;
|
||||
assert sumOfDigits(-123) == 6 && sumOfDigitsRecursion(-123) == 6 && sumOfDigitsFast(-123) == 6;
|
||||
|
||||
assert sumOfDigits(0) == 0 && sumOfDigitsRecursion(0) == 0 && sumOfDigitsFast(0) == 0;
|
||||
|
||||
assert sumOfDigits(12345) == 15 && sumOfDigitsRecursion(12345) == 15
|
||||
&& sumOfDigitsFast(12345) == 15;
|
||||
assert sumOfDigits(12345) == 15 && sumOfDigitsRecursion(12345) == 15 && sumOfDigitsFast(12345) == 15;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,7 @@ public class TrinomialTriangle {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (
|
||||
TrinomialValue(n - 1, k - 1) + TrinomialValue(n - 1, k) + TrinomialValue(n - 1, k + 1));
|
||||
return (TrinomialValue(n - 1, k - 1) + TrinomialValue(n - 1, k) + TrinomialValue(n - 1, k + 1));
|
||||
}
|
||||
|
||||
public static void printTrinomial(int n) {
|
||||
|
Reference in New Issue
Block a user