Constants are identified (in fixed format) in Java using the combination of public static final.
The default value set by the system is invalidated by the construction method before the construction method is used to assign a value to the constructor using final.
Constants (constants here refer to the assignment of instance constants: That is, member variables):
① is assigned by an explicit declaration at initialization time. Final int x=3;
The ② is assigned at the time of construction.
Local variables can be assigned at any time.
1 PackageTomtext;2 //use the IF statement to determine whether a year is a leap years. 3 Public classtomtext_28 {4 Public Static voidMain (String args[]) {5 6 //The first way7 intYear = 1989;8 if((Year% of 4 ==0 && year% 100! = 0) | | (Year% 400 ==0)){9SYSTEM.OUT.PRINTLN (Year + "was a leap year."));Ten}Else{ OneSYSTEM.OUT.PRINTLN (year + "isn't a leap year.")); A } - - //The second way theYear = 2000; - BooleanLeap; - if(year% 4! = 0){ -Leap =false; +}Else if(year% 100! = 0){ -Leap =true; +}Else if(Year% 400! = 0){ ALeap =false; at}Else{ -Leap =true; - } - if(Leap = =true){ -SYSTEM.OUT.PRINTLN (Year + "was a leap year.")); -}Else{ inSYSTEM.OUT.PRINTLN (year + "isn't a leap year.")); - } to + //The Third Way -Year =2050; the if(year% 4 = = 0){ * if(year% 100 = = 0){ $ if(Year% 400 = = 0){Panax NotoginsengLeap =true; -}Else{ theLeap =false; + } A}Else{ theLeap =false; + } -}Else{ $Leap =false; $ } - if(Leap = =true){ -SYSTEM.OUT.PRINTLN (Year + "was a leap year.")); the}Else{ -SYSTEM.OUT.PRINTLN (year + "isn't a leap year."));Wuyi } the } - Wu}
Identify constants in Java using the combination of public static final