Code Snippets
Runnable Java code examples for testers: arrays, numbers and strings, with output and common mistakes.
Check Harshad Number in Java: Logic + Full Code (2026)
Learn how to check Harshad (Niven) numbers in Java by testing divisibility by the digit sum, with full code, examples, and interview FAQs.
Check Happy Number in Java: Logic + Cycle Detection (2026)
Learn how to check happy numbers in Java using sum of squared digits, with HashSet-based and Floyd's cycle detection to avoid infinite loops, plus FAQs.
Calculate Compound Interest in Java: Formula + Full Code (2026)
Learn how to calculate compound interest in Java using Math.pow, with support for different compounding frequencies, year-by-year breakdowns, and FAQs.
Calculate Simple Interest in Java: Formula + Full Code (2026)
Learn how to calculate simple interest in Java using the standard formula, with user input via Scanner, correct decimal formatting, and FAQs.
Convert Binary to Decimal in Java: 4 Methods Explained (2026)
Learn how to convert binary numbers to decimal in Java using a while loop, recursion, and Integer.parseInt, with positional notation explained and FAQs.
Convert Decimal to Binary in Java: 4 Methods Explained (2026)
Learn how to convert decimal numbers to binary in Java using a while loop, recursion, StringBuilder, and Integer.toBinaryString, with FAQs and examples.
Find Smallest and Largest Digit in a Number in Java (2026)
Learn how to find the smallest and largest digit in a number using Java, with a while loop, Math.max/min, recursion, and negative number handling.
Print Numbers Without Loop in Java: Recursion (1 to N & N to 1)
Learn how to print numbers from 1 to N and N to 1 in Java without using any loop, using pure recursion, with clear call-stack traces and FAQs.
Reverse a Number Without Loop in Java: Using Recursion (2026)
Learn how to reverse a number in Java without using any loop, relying purely on recursion, with a clean return-based design and interview FAQs.
Check Neon Number in Java: Logic + Full Code Explained (2026)
Learn how to check neon numbers in Java by squaring the number and summing the digits of the result, with full code, examples, and FAQs.
Sum of First N Natural Numbers in Java: Loop vs Formula
Learn how to find the sum of the first N natural numbers in Java using a loop, recursion, and the efficient Gauss formula, with FAQs and examples.
Palindrome Numbers in a Range in Java: Efficient Code (2026)
Learn how to find all palindrome numbers within a given range in Java using a reusable method, Streams, and an approach to find the largest one, with FAQs.
Armstrong Numbers in a Range in Java: Efficient Code (2026)
Learn how to find and print all Armstrong numbers within a given range in Java, using a reusable, efficient digit-count-aware method, with FAQs.
Find Factors of a Number in Java: Brute Force vs Optimized
Learn how to find and print all factors of a number in Java using brute force and the square-root-optimized method, with sorted output and FAQs.
Find LCM of Two Numbers in Java: Using GCD (Efficient Method)
Learn how to find the LCM of two numbers in Java using brute force and the efficient GCD-based formula, with code, math explanation, and FAQs.
Find GCD (HCF) of Two Numbers in Java: Euclidean Algorithm
Learn how to find the GCD (HCF) of two numbers in Java using brute force and the efficient Euclidean algorithm, with recursion, code, and FAQs.
Sum of Even and Odd Numbers in Java: Array & Range Methods
Learn how to find the sum of even and odd numbers in Java using loops, arrays, and Java Streams, plus mathematical shortcut formulas, with FAQs.
Print Fibonacci Series in Java: Loop, Recursion & Memoization
Learn to print the Fibonacci series in Java using a loop, naive recursion, and memoization — with time complexity comparisons and interview FAQs.
Check Strong Number in Java: Logic + Full Code Explained (2026)
Learn how to check strong numbers in Java by summing the factorial of each digit, with full code, step-by-step traces, and interview FAQs.
Check Perfect Number in Java: Logic, Code & Optimized Method
Learn how to check perfect numbers in Java using proper divisors, with a brute-force and square-root-optimized approach, plus FAQs and examples.