首页 技术 正文
技术 2022年11月9日
0 收藏 381 点赞 4,269 浏览 886 个字

在JAVA中利用public static final的组合方式对常量进行标识(固定格式)。

对于在构造方法中利用final进行赋值的时候,此时在构造之前系统设置的默认值相对于构造方法失效。

常量(这里的常量指的是实例常量:即成员变量)赋值:

①在初始化的时候通过显式声明赋值。Final int x=3;

②在构造的时候赋值。

局部变量可以随时赋值。

 package TomText;
//利用if语句,判断某一年是否是闰年。
public class TomText_28 {
public static void main(String args[]){ //第一种方式
int year = 1989;
if ((year % 4 ==0 && year % 100 != 0) || (year % 400 ==0)){
System.out.println(year + "is a leap year.");
}else{
System.out.println(year + "is not a leap year.");
} //第二种方式
year = 2000;
boolean leap;
if (year % 4 != 0){
leap = false;
}else if(year % 100 != 0){
leap = true;
}else if(year % 400 != 0){
leap = false;
}else{
leap = true;
}
if(leap == true){
System.out.println(year + "is a leap year.");
}else{
System.out.println(year + "is not a leap year.");
} //第三种方式
year =2050;
if(year % 4 == 0){
if(year % 100 == 0){
if(year % 400 == 0){
leap = true;
}else{
leap = false;
}
}else{
leap = false;
}
}else{
leap = false;
}
if(leap == true){
System.out.println(year + " is a leap year.");
}else{
System.out.println(year + " is not a leap year.");
}
} }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901