🆕 Free Interactive Selenium, Playwright & API tools — no signup — Start Free Automation Roadmap →
📁
All Topics › Code Snippets

Code Snippets

Runnable Java code examples for testers: arrays, numbers and strings, with output and common mistakes.

124 Articles
123 Beginner
1 Intermediate
Beginner 📅 Jul 15, 2026 👁 46 views

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.

Beginner 📅 Jul 15, 2026 👁 44 views

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.

Beginner 📅 Jul 15, 2026 👁 51 views

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.

Beginner 📅 Jul 15, 2026 👁 52 views

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.

Beginner 📅 Jul 15, 2026 👁 53 views

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.

Beginner 📅 Jul 15, 2026 👁 49 views

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.

Beginner 📅 Jul 15, 2026 👁 49 views

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.

Beginner 📅 Jul 15, 2026 👁 48 views

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.

Beginner 📅 Jul 15, 2026 👁 50 views

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.

Beginner 📅 Jul 15, 2026 👁 57 views

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.

Beginner 📅 Jul 15, 2026 👁 69 views

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.

Beginner 📅 Jul 15, 2026 👁 53 views

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.

Beginner 📅 Jul 14, 2026 👁 52 views

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.

Beginner 📅 Jul 14, 2026 👁 52 views

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.

Beginner 📅 Jul 14, 2026 👁 56 views

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.

Beginner 📅 Jul 14, 2026 👁 71 views

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.

Beginner 📅 Jul 14, 2026 👁 53 views

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.

Beginner 📅 Jul 14, 2026 👁 56 views

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.

Beginner 📅 Jul 14, 2026 👁 40 views

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.

Beginner 📅 Jul 14, 2026 👁 54 views

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.

View all 124 Code Snippets articles on one page →