Java programming: enumerate the days in a week.
Package enumeration; public class WeekDaysList {public static void main (String [] args) {// TODO Auto-generated method stubSystem. out. println ("Days of week:"); for (DaysOfTheWeek day: DaysOfTheWeek. the values () // values method returns an array containing an enumerated Constant list. System. out. printf ("% s", day); // The toString method will automatically call day. toString () is the same. system. out. println () ;}}// enumerate enum DaysOfTheWeek {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, STAURDAY, SUNDAY; @ Overridepublic String toString () // override the parent class method. This method will automatically call {String s = super. toString (); // use toString to obtain the string representation of each constant. Return s. substring (0, 1) + s. substring (1). toLowerCase (); // keep the first letter of the string, and convert the remaining letters to lowercase letters .}}
Note: substring (0, 1) indicates that the first character is returned, that is, the value 0 does not include 1;
Substring (1) indicates that the index starts from the specified 1.EndIndex-1
Character