MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

/*
 * Output:
250 days remain in current year 
 */

import java.util.Calendar;
import java.util.GregorianCalendar;

public class MainClass {

    public static void main(String args[]) {

        Calendar calendar1 = Calendar.getInstance();
        int doy1 = calendar1.get(Calendar.DAY_OF_YEAR);

        int year = calendar1.get(Calendar.YEAR);

        Calendar calendar2 = new GregorianCalendar(year, 11, 31);
        int doy2 = calendar2.get(Calendar.DAY_OF_YEAR);

        int days = doy2 - doy1;
        System.out.println(days + " days remain in current year");
    }
}