Number Crunching (Digit Manipulation) and Number Based Problems
Number Crunching (Digit Manipulation) and Number Based Problems
Below are different scenarios and their implementations in Java for number crunching using digit
manipulation:
1. Left-Side Formation
In left-side formation, the number is reconstructed starting from the most significant digit (leftmost
digit) to the least significant digit. Each new digit is added to the left of the current result.
Reverse a Number
Sum of Digits
Count Digits
Check For Palindrome
Multiplication of Digits
Find Largest Digit
Find Smallest Digit
Check If All Digits Are Even
Digit manipulation
Reverse a Number
Reverse the digits of a number.
Output:
54321
Digit manipulation
Sum of Digits
Add all digits of a number.
Output:
15
Digit manipulation
Count Digits
Count the number of digits in a number.
Output:
5
Digit manipulation
Output:
Palindrome
Digit manipulation
Multiplication of Digits
Find the product of all digits.
Output:
24
Digit manipulation
Find Largest Digit
Determine the largest digit in a number.
Output:
9
Digit manipulation
Find Smallest Digit
Determine the smallest digit in a number.
Output:
2
Digit manipulation
Check if All Digits Are Even
Verify if all digits in the number are even.
Output:
All digits are even
Number Based Problems
Check if a Number is Prime
A prime number is only divisible by 1 and itself.
public class PrimeCheck {
public static void main(String[] args) {
int num = 29; // Change to test different numbers
boolean isPrime = true;
if (num <= 1) {
isPrime = false;
} else {
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
}
System.out.println(num + (isPrime ? " is a prime number." : " is not a prime."));
}
}
Number Based Problems
Find the Factorial of a Number
The factorial of n is the product of all positive integers up to n.
java_NB_L0_1 factors
java_NB_L0_2 Factor count
java_NB_L0_3 sum of factors
java_NB_L0_4 Perfect number
java_NB_L0_5 ABUNDANT,PERFECT,DEFICIENT NUMBER
java_NB_L0_6 amicable pair
java_NB_L0_7 BETROTHED NUMBER
java_NB_L0_8 Print factors in pairs
java_NB_L0_9 GCD of 2 nos
java_NB_L0_1O LCM
Number Based Problems