Write code that creates an array of Dates with the name of \"dateArr\". Use the
ID: 3547162 • Letter: W
Question
Write code that creates an array of Dates with the name of "dateArr".
Use the Date.java class found in chapter 5 of your textbook. An electronic
version can be found on my web site under "Absolute Java text/chap05".
The array should have 4 entries and the entries should be filled with
Date classes representing the dates:
May 16, 1984
November 14, 1978
September 21, 1980
July 3, 1987
Print the values of the dateArr array backwards.
Your Date classes can be printed using the toString() method in the Date class.
Absolute Java text/chap05 is below
Explanation / Answer
public class DateTest {
public static void main(String args[]){
Date []dateArr = new Date[4];
dateArr[0] = new Date("May",16,1984);
dateArr[1] = new Date("November",14,1978);
dateArr[2] = new Date("September",21,1980);
dateArr[3] = new Date("July",3,1987);
System.out.println("Printing the dates in reverse order.");
for(int i=3;i>=0;i--){
System.out.println(dateArr[i]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.