The term “Julian day” is used loosely to mean the day of the year, meaning a number from 1 to 365 or 366 (leap years). January 1 is  1 , January 2 is 2, December 31 is 365 (or 366 in leap years).

watch basic java videos here
www.youtube.com/user/trushntej

Write a program to accept a date in dd mm yyyy format, and print the Julian day.

import java.io.*;
public class JulianNumber
{
    int d,m,y;
    int n;
    void input()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the date in dd mm yyyy format");
        d=Integer.parseInt(br.readLine());
        m=Integer.parseInt(br.readLine());
        y=Integer.parseInt(br.readLine());
        if(m<=12&&d<=31)
        {
            compute();
        }
        else
            System.out.println("Invalid date");
    }

    void compute()
    {
        int arr[]={31,28,31,30,31,30,31,31,30,31,30,31};
        if(y%4==0)
            arr[1]=29;
        for(int i=0;i<m-1;i++)
        { 
            n+=arr[i];
        }
        n=n+d;
        System.out.println("The Julian day is:   "+n);
    }

    public static void main()throws IOException
    {
        JulianNumber obj=new JulianNumber();
        obj.input();
    }
}

Output:
Enter the date in dd mm yyyy format
01
02
2020
The Julian day is :32

Take a look at some other java programs:
https://java4school.com/sum-of-boundary-elements-of-a-matrix

LEAVE A REPLY

Please enter your comment!
Please enter your name here