Constructors BigInteger and BigDecimal used to wrap primitives should never be used. (#3627)

Constructors BigInteger and BigDecimal used to wrap primitives should never be used.

Co-authored-by: Debasish Biswas <debasishbsws.abc@gmail.com>
This commit is contained in:
kongleong86 2022-11-06 12:10:14 +00:00 committed by GitHub
parent cc17d60d5c
commit c8ecd23183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 16 deletions

View File

@ -2438,16 +2438,16 @@ public class AES {
public static BigInteger[] keyExpansion(BigInteger initialKey) { public static BigInteger[] keyExpansion(BigInteger initialKey) {
BigInteger[] roundKeys = { BigInteger[] roundKeys = {
initialKey, initialKey,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
new BigInteger("0"), BigInteger.ZERO,
}; };
// initialize rcon iteration // initialize rcon iteration

View File

@ -63,7 +63,7 @@ public class RSA {
publicKey = BigInteger.valueOf(3L); publicKey = BigInteger.valueOf(3L);
while (m.gcd(publicKey).intValue() > 1) { while (m.gcd(publicKey).intValue() > 1) {
publicKey = publicKey.add(BigInteger.valueOf(2L)); publicKey = publicKey.add(BigInteger.TWO);
} }
privateKey = publicKey.modInverse(m); privateKey = publicKey.modInverse(m);

View File

@ -10,7 +10,7 @@ public class KaprekarNumbers {
digits and sum of these parts is equal to the original number. */ digits and sum of these parts is equal to the original number. */
// Provides a list of kaprekarNumber in a range // Provides a list of kaprekarNumber in a range
public static ArrayList<Long> kaprekarNumberInRange(long start, long end) public static List<Long> kaprekarNumberInRange(long start, long end)
throws Exception { throws Exception {
long n = end - start; long n = end - start;
if (n < 0) throw new Exception("Invalid range"); if (n < 0) throw new Exception("Invalid range");
@ -26,12 +26,12 @@ public class KaprekarNumbers {
// Checks whether a given number is Kaprekar Number or not // Checks whether a given number is Kaprekar Number or not
public static boolean isKaprekarNumber(long num) { public static boolean isKaprekarNumber(long num) {
String number = Long.toString(num); String number = Long.toString(num);
BigInteger originalNumber = new BigInteger(number); BigInteger originalNumber = BigInteger.valueOf(num);
BigInteger numberSquared = originalNumber.multiply(originalNumber); BigInteger numberSquared = originalNumber.multiply(originalNumber);
if (number.length() == numberSquared.toString().length()) { if (number.length() == numberSquared.toString().length()) {
return number.equals(numberSquared.toString()); return number.equals(numberSquared.toString());
} else { } else {
BigInteger leftDigits1 = new BigInteger("0"); BigInteger leftDigits1 = BigInteger.ZERO;
BigInteger leftDigits2; BigInteger leftDigits2;
if (numberSquared.toString().contains("0")) { if (numberSquared.toString().contains("0")) {
leftDigits1 = leftDigits1 =

View File

@ -2,7 +2,8 @@ package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList; import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class KaprekarNumbersTest { public class KaprekarNumbersTest {
@ -50,7 +51,7 @@ public class KaprekarNumbersTest {
@Test @Test
void testForRangeOfNumber() { void testForRangeOfNumber() {
try { try {
ArrayList<Long> rangedNumbers = KaprekarNumbers.kaprekarNumberInRange( List<Long> rangedNumbers = KaprekarNumbers.kaprekarNumberInRange(
1, 1,
100000 100000
); );