chapter_12_beginning_javabook

method indexof returns the value 1 only when it

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the same format specifiers as the method System.out.printf(). This boolean expression tests whether the object referenced by date_to_incrememt contains a nice wedding date. The beginning of the if construct could be put into words like: "If the day of the date and the month of the date contain only such digits that can be found in the year of the date, ...". Method indexOf() returns the value -1 only when it cannot find the given character in the string for which it was called. For example, date 02/06/2006 would be found to be an acceptable wedding date because all digits in strings "02" and "06" can be found in string "2006". while ( number_of_dates_printed < { String day_as_string = String.format( "%02d", String month_as_string = String.format( "%02d", String year_as_string = "" + 393 60 ) date_to_increment.day() ) ; date_to_increment.month() ) ; date_to_increment.year() ; if ( year_as_string.indexOf( day_as_string.charAt( 0 ) ) != -1 && year_as_string.indexOf( day_as_string.charAt( 1 ) ) != -1 && year_as_string.indexOf( month_as_string.charAt( 0 ) ) != -1 && year_as_string.indexOf( month_as_string.charAt( 1 ) ) != -1 ) { // Now we have found a date that meets our requirements. Weddingdates.java - 1 -1. The mechanism to find a nice wedding date. D:\javafiles3>java Weddingdates These are easy-to-remember dates for weddings and other important events because the days and months consist of the digits used in the year: 02/02/2006 06/02/2006 02/02/2007 07/02/2007 02/02/2008 08/02/2008 02/02/2009 09/09/2009 01/02/2010 01/21/2010 02/11/2010 10/01/2010 02/06/2006 06/06/2006 02/07/2007 07/07/2007 02/08/2008 08/08/2008 02/09/2009 09/20/2009 01/10/2010 01/22/2010 02/12/2010 10/02/2010 02/20/2006 06/20/2006 02/20/2007 07/20/2007 02/20/2008 08/20/2008 02/20/2009 09/22/2009 01/11/2010 02/01/2010 02/20/2010 10/10/2010 02/22/2006 06/22/2006 02/22/2007 07/22/2007 02/22/2008 08/22/2008 02/22/2009 09/29/2009 01/12/2010 02/02/2010 02/21/2010 10/11/2010 02/26/2006 06/26/2006 02/27/2007 07/27/2007 02/28/2008 08/28/2008 09/02/2009 01/01/2010 01/20/2010 02/10/2010 02/22/2010 10/12/2010 Weddingdates.java - X. The program prints 60 dates in the MM/DD/YYYY format....
View Full Document

Ask a homework question - tutors are online