/* */ public class Misc2 { public static void main(String[] args) { test1( ); test2( ); test3( ); } public static void printArray( String title, Object[] o ) { System.out.println( title ); for (int i = 0; i < o.length; i++ ) System.out.println( " [" + i + "] = " + ( o[i] == null ? "null" : o[i].toString() ) ); } public static void test1( ) { String[ ] greatCities = new String[5]; greatCities[2] = new String( "Paris" ); greatCities[0] = "Tokyo"; greatCities[4] = "Beltsville"; greatCities[1] = greatCities[2]; int k = 4; int x = greatCities[k].length( ); char c = greatCities[2].charAt( 2 ); printArray( "greatCities:", greatCities ); System.out.println( " x = " + x ); System.out.println( " c = " + c ); String[ ] moreCities = { "New York", "Boston", "Kathmandu" }; printArray( "moreCities", moreCities ); String[ ] cityState = { moreCities[0] + ", NY", moreCities[1] + ", MA" }; printArray( "cityState", cityState ); Date[ ] birthDays = { new Date( 2, 12, 1809 ), new Date( 4, 30, 1789 ) }; printArray( "birthDays", birthDays ); } public static void test2( ) { } public static void test3( ) { } } class Date { private int month; // the month (from 1-12) private int day; // the day of the month private int year; // the year (four digits) public Date( int m, int d, int y ) { month = m; day = d; year = y; } public String toString( ) { return new String( month + "/" + day + "/" + year ); } public boolean equals( Date d ) { return ( ( year == d.year ) && ( month == d.month ) && ( day == d.day ) ); } }