🆕 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.

123 Articles
123 Beginner
1 Intermediate
Beginner 📅 Jul 14, 2026 👁 57 views

Check Palindrome Number in Java: Full Code + Logic (2026)

Learn how to check if a number is a palindrome in Java using a while loop, recursion, and StringBuilder — with full code, traces, and interview FAQs.

Beginner 📅 Jul 14, 2026 👁 99 views

Check Prime Number in Java: Optimized Code (sqrt(n) Method)

Learn how to check if a number is prime in Java using brute force and the optimized square-root method, plus how to print primes in a range with FAQs.

Beginner 📅 Jul 14, 2026 👁 61 views

Check Leap Year in Java: Simple Logic + Full Code (2026)

Learn the exact leap year rule and how to check leap year in Java using if-else and ternary operators, including the century-year exception, with FAQs.

Beginner 📅 Jul 14, 2026 👁 62 views

Find Power of a Number in Java: Loop, Math.pow() & Recursion

Learn how to calculate the power of a number in Java using a loop, Math.pow(), recursion, and fast exponentiation — with code, output, and FAQs.

Beginner 📅 Jul 14, 2026 👁 99 views

Find Factorial of a Number in Java: Loop, Recursion & BigInteger

Learn how to find the factorial of a number in Java using a for loop, while loop, recursion, and BigInteger for large numbers — with code and FAQs.

Beginner 📅 Jul 14, 2026 👁 65 views

Count Number of Digits in Java: 4 Methods (Loop, String, Log10)

Learn 4 ways to count the number of digits in an integer in Java — while loop, String.length(), Math.log10(), and recursion — with code and FAQs.

Beginner 📅 Jul 14, 2026 👁 55 views

Sum of Digits in Java: While Loop, Recursion & Optimized Code

Learn how to find the sum of digits of a number in Java using a while loop and recursion, including how to reduce it to a single digit (digital root).

Beginner 📅 Jul 14, 2026 👁 49 views

Reverse a Number in Java: 4 Methods (Loop, Recursion, StringBuilder)

Learn to reverse a number in Java using a while loop, recursion, and StringBuilder. Includes step-by-step traces, output, and common interview mistakes.

Beginner 📅 Jul 14, 2026 👁 59 views

Find the Largest Among 3 Numbers in Java (4 Methods + Code)

Learn how to find the largest of three numbers in Java using if-else, nested if, Math.max, and ternary operators. Includes code, output, and FAQs.

Beginner 📅 Jul 14, 2026 👁 64 views

Swap Two Numbers in Java: With and Without a Third Variable (2026 Guide)

Learn to swap two numbers in Java using a temp variable, arithmetic operators, and XOR — with code, output, memory explanation, and interview tips.

Beginner 📅 Jul 14, 2026 👁 84 views

Check Positive, Negative, or Zero in Java (Code + Interview Answer)

Step-by-step Java program to check if a number is positive, negative, or zero. Includes if-else logic, ternary version, memory explanation, and FAQs.

Beginner 📅 Jul 14, 2026 👁 72 views

How to Check Even or Odd Number in Java (5 Easy Methods + Code)

Learn how to check even or odd numbers in Java using modulus, bitwise, and ternary operators. Includes code, output, interview answers, and common mistakes.

Beginner 📅 Jul 14, 2026 👁 56 views

Display Upper and Lower Triangular Matrix Elements in Java

Learn how to display the upper and lower triangular elements of a matrix in Java, with correct index conditions and full code examples.

Beginner 📅 Jul 14, 2026 👁 49 views

Check if a Matrix Is an Identity Matrix in Java (Full Guide)

Learn how to check whether a matrix is an identity matrix in Java, verifying both the diagonal and off-diagonal elements correctly.

Beginner 📅 Jul 14, 2026 👁 48 views

Multiply Two Matrices in Java (Full Guide With Dimension Rules)

Learn how to multiply two matrices in Java using triple nested loops, understand dimension compatibility rules, and avoid common mistakes

Beginner 📅 Jul 14, 2026 👁 56 views

Find the Sum of Diagonal Elements of a Matrix in Java (Both Diagonals)

Learn how to find the sum of both diagonals in a Java matrix, avoiding the classic double-counting bug for odd-sized matrices.

Beginner 📅 Jul 14, 2026 👁 63 views

Print Diagonal Elements of a Matrix in Java (Both Diagonals)

Learn how to print the main and anti-diagonal elements of a matrix in Java, with the index formulas explained clearly for each.

Beginner 📅 Jul 14, 2026 👁 68 views

Find the Transpose of a Matrix in Java (In-Place & New Matrix Methods)

Learn how to find the transpose of a matrix in Java for both square and non-square matrices, including the in-place swap technique.

Beginner 📅 Jul 14, 2026 👁 54 views

Find Sum of Each Column in 2D Array in Java

Learn how to calculate the sum of each column in a Java 2D array using nested loops with swapped iteration order, and streams.

Beginner 📅 Jul 14, 2026 👁 56 views

Find the Sum of Each Row in a 2D Array in Java (Step-by-Step)

Learn how to calculate the sum of each row in a Java 2D array using nested loops and streams, with full code examples and jagged array support.

View all 123 Code Snippets articles on one page →