All pastes #331535 Raw Edit

Unnamed

public text v1 · immutable
#331535 ·published 2007-01-28 23:49 UTC
rendered paste body
import java.io.*;

public class DateConverter {
	
	public static void main (String [ ] args) {
		// This is the contents of a main method that reads a day number in 2004,
		// an integer between 1 and 366, and prints the date in month/day format.
		// The code is missing two assignment statements;
		// they should be inserted at one or both of the lines
		// marked with a ***.
		// Don't change any of the remaining code.
		BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));
		while (true) {
			int dayOfYear = 0;
			try {
				dayOfYear = Integer.parseInt (keyboard.readLine ( ));
			} catch (NumberFormatException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			int month, dateInMonth, daysInMonth;
			month = 1;
			daysInMonth = 31;
			while (dayOfYear > daysInMonth) {
				
				dayOfYear -= daysInMonth;
                                ++month;
				
				// end of added stuff
				
				if (month == 2) {
					daysInMonth = 29;
				} else if (month == 4 || month == 6 || month == 9 || month == 11) {
					daysInMonth = 30;
				} else {
					daysInMonth = 31;
				}
				
			}
			
			dateInMonth = dayOfYear;
			System.out.println (month + "/" + dateInMonth);
		}
	}
}