Member-only story

Decoding Truncatable Primes in Java

A beginner’s guide to understanding and implementing truncatable primes

Max N
3 min readJun 18, 2023
Photo by Markus Krisetya on Unsplash

Welcome to this tutorial on solving the Truncatable Primes problem in Java. This problem involves prime numbers that remain prime when digits are successively removed from the left or right. By the end of this guide, you’ll be able to write a function that identifies whether a given number is a left-truncatable prime, a right-truncatable prime, both, or neither. Let’s get started!

Step 1: Understanding the Problem

The first step in solving any programming problem is understanding what the problem is asking. In this case, we’re given an integer and we need to determine if it’s a left-truncatable prime, a right-truncatable prime, both, or neither.

Step 2: Breaking Down the Problem

To solve this problem, we need to break it down into smaller, manageable tasks:

  1. Check if the number is a prime.
  2. Check if the number remains a prime when digits are successively removed from the left.
  3. Check if the number remains a prime when digits are successively removed from the right.

Step 3: Implementing the Solution

--

--

Max N
Max N

Written by Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.

No responses yet