About robin

I am a Computer Science Teacher from India. Blogging is my hobby.

Distinct Prime Digit Integer | ISC Computer Science 2026 Sample Paper

A distinct prime digit integer is a positive (without leading zeros) in which all digits are prime numbers and no digit is repeated. The prime digits are 2, 3, 5, 7. For example, 2, 37, 253 are distinct prime digit integers, whereas 33, 252, 29 are not.

Given two positive integers m and n, where m < n, write a program to determine how many distinct prime digit integers are there in the range between m and n (both inclusive) and output them.

Test your program for the following data and some random data:

Example 1:
INPUT:
m = 20
n = 60
OUTPUT:
THE DISTINCT PRIME DIGIT INTEGERS ARE:
23, 25, 27, 32, 35, 37, 52, 53, 57
FREQUENCY OF DISTINCT PRIME DIGIT INTEGERS IS: 9

Example 2:
INPUT:
m = 70
n = 120
OUTPUT:
THE DISTINCT PRIME DIGIT INTEGERS ARE:
72, 73, 75
FREQUENCY OF DISTINCT PRIME DIGIT INTEGERS IS: 3

Example 3:
INPUT:
m = 100
n = 180
OUTPUT:
THE DISTINCT PRIME DIGIT INTEGERS ARE: NIL
FREQUENCY OF DISTINCT PRIME DIGIT INTEGERS IS: 0

Example 4:
INPUT:
m = 200
n = 150
OUTPUT:
INVALID INPUT

import java.util.Scanner;
class Distinct{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("m = ");
        int m = in.nextInt();
        System.out.print("n = ");
        int n = in.nextInt();
        if(m >= n){
            System.out.println("INVALID INPUT");
            return;
        }
        int freq = 0;
        System.out.print("THE DISTINCT PRIME DIGIT INTEGERS ARE: ");
        for(int i = m; i <= n; i++){
            boolean status = true;
            String s = String.valueOf(i);
            for(int j = 0; j < s.length(); j++){
                char ch = s.charAt(j);
                if("2357".indexOf(ch) == -1 || s.substring(0, j).indexOf(ch) >= 0){
                    status = false;
                    break;
                }
            }
            if(status){
                freq++;
                if(freq == 1)
                    System.out.print("\n" + i);
                else
                    System.out.print(", " + i);
            }
        }
        if(freq == 0)
            System.out.print("NIL");
        System.out.println("\nFREQUENCY OF DISTINCT PRIME DIGIT INTEGERS IS: " + freq);
    }
}