Find Season Program in Java Solution

Find Season

Question

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 its 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.*;
class Season{
    public static void main(String[] args){
        //String a[]={"Spring","Summer","Autumn","Winter"};
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the month:");
        int month =  sc.nextInt();
        if(month >=1 && month <=12){
        if(month>=3 && month<=5)
            System.out.println("Season:Spring");
        else if(month>=6 && month<=8)
            System.out.println("Season:Summer");
        else if(month>=9 && month<=11)
            System.out.println("Season:Autumn");
        else
            System.out.println("Season:Winter");
        }
        else{
            System.out.println("Invalid month");
        }
    }
}

Leave a Comment

Scroll to Top