Jump to content

Rosetta Code:Add a Task: Difference between revisions

→‎Example code: --any specific day on every month for specific years
(→‎Example code: --any specific day on every month for specific years)
Line 88:
Where relevant, '''sample input''' should be included; it gives task solvers something to work with.
 
package com.deere.core.dates;
===Example code===
It is usually a good idea to '''have at least one example implementation completed, tested, and working''' ''before'' you start writing the description of the task, as well as '''a sample of correct output.''' It is usually a good idea if this first example shows its output; even if it isn't strictly necessary for the completion of the task, it helps other implementers understand the task and what they need to do.
 
import java.text.DateFormatSymbols;
In short, solve your own task. Show us how it's done.
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Scanner;
 
public class LastSunday {
 
/**
* Venkata Janga
* @param args
*/
public static void main(String[] args) {
System.out.println("Please enter year to want to see........");
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
System.out.println("Please enter how many years you want to see the dates");
Scanner yearEnd = new Scanner(System.in);
int endYear = yearEnd.nextInt();
for(int year1=year;year1<=endYear;year1++){
GregorianCalendar calander = new GregorianCalendar(year, 0, 1);
System.out.println("===================================================Begin");
for (String mon : new DateFormatSymbols(Locale.US).getShortMonths()) {
if (!mon.isEmpty()) {
int totalDaysOfMonth = calander.getActualMaximum(Calendar.DAY_OF_MONTH);
calander.set(Calendar.DAY_OF_MONTH, totalDaysOfMonth);
/**
* 1--> FRIDAY
* 2--> THURSDAY
* 3--> WEDNES DAY
* 4--> TUESDAY
* 5--> MONAY
* 6--> SUNDAY
* 7--> SATURADAY
* */
int daysToRollBack = (calander.get(Calendar.DAY_OF_WEEK) + 6) % 7;
int day = totalDaysOfMonth - daysToRollBack;
calander.set(Calendar.DAY_OF_MONTH, day);
System.out.printf("%d %s %d\n", year1, mon, day);
calander.set(year,calander.get(Calendar.MONTH) + 1, 1);
}
}
System.out.println("===================================================End");
}
}
 
}
 
==Additional information==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.