Java Lucky Number program


William planned to choose a four-digit lucky number for his car. His lucky numbers are 3,5 and 7. Help him find the number, whose sum is divisible by  3 or 5 or 7.
Provide a valid car number, Fails to provide a valid input then display that number is not a valid car number. 

Note : The input other than 4 digit positive number[includes negative and 0] is considered as invalid.

Refer the samples, to read and display the data.

Sample Input 1:
Enter the car no:1234

Sample Output 1:
Lucky Number

Sample Input 2:

Enter the car no:1214

Sample Output 2:

Sorry it’s not my lucky number

Sample Input 3:

Enter the car no:14

Sample Output 3:

14 is not a valid car number

Code :-

import java.util.Scanner;
public class LuckyNum
    public static void main (String[] args) {
        Scanner sc= new Scanner(;
        System.out.println("Enter the car no:");
        int num=sc.nextInt();
        if(num<1000 || num>9999)
            System.out.println(num+" is not a valid car number");
        {int sum=0;
            if(sum%3==0 || sum%5==0 || sum%7==0)
                System.out.println("Lucky Number");
                System.out.println("Sorry its not my lucky number");


  1. Pencil Count
  2. Repetition of a Number
  3. Bonus Points – Bike Race
  4. Celcius to Farenheit Conversion
  5. Check for Leap Year

2 thoughts on “Java Lucky Number program”

Leave a Comment

Your email address will not be published. Required fields are marked *