一、标识符(规则)
1、标识符是由字母、数字、下划线(-) 和美元符号($)构成的字符序列。
2、标识符必须以字母、下划线(_)或美元符号($)开头,不能以数字开头。
3、标识符不能是保留字(参见附录 A 中的保留字列表)。
4、标识符不能是 true、false 或 null。
5、标识符可以为任意长度
二、幂方法
Math.pow(a,b)来计算 a^b
三、操作符优先级
在 Java中,两个整数相除商为整数。如:将5/9转换为5.0 /9 ,因为在 Java中 5/9的结果是 0.
四、增强赋值操作符
五、自增和自减操作符
如:a=i++,就是先赋值再相加即a=i;i=i+1;
a=++i,就是先相加再赋值即i=i+1;a=i;
六、显示当前时间
System类中的方法 currentTimeMillis 返回从 GMT (格林威治标准时间)1970年 1 月 1 日 00:00:00 开始到 当前时刻的毫秒数
1 )调用System.currentTimeMillisO 方法获取1970年丨月 1 日午夜到现在的毫秒数(例 如:1203183086328 毫秒),并存放在变童 totalMilliseconds 中。
2) 通过将总毫秒数 totalMilliseconds 除以 1000 得到总秒数 totalSeconds (例如: 120B183086328 毫秒 /1000=1203183068 秒)。
3 ) 通过 totalSecondsX60 得到当前的秒数(例如:lMSlHO68 秒%60=8,这个值就是 当前秒数)。
4 ) 通过将 totalSeconds 除以 M得到总的分钟数 totalMinutes (例如:lWU83。 68 秒 /60=20053051分钟)。
5 ) 通过 totalMinutesX60 得到当前分钟数(例如:20053051分钟%60=31, 这个值就是 当前分钟数)。
6 ) 通过将总分钟数 totalMinutes 除以 60 获得总的小时数 totalHours (例如:MOSSOSl 分钟 /60=334217 小时)。
7 ) 通过 t0talH0UrSX24 得到当前的小时数(例如:33«17小时%24=17, 该值就是当前 小时数)
public class ShowCurrentTime {
public static void main(String[] args) {
// Obtain the total miHiseconds since midnight, 3an 1 , 1970
long totalMilliseconds * System.currentTimeMi11is();//距当前的总毫秒数
// Obtain the total seconds since midnight, Jan 1 , 1970
long totalSeconds = totalMilliseconds / 1000;//总秒数
// Compute the current second in the minute in the hour
long currentSecond = totalSeconds % 60; //当前秒数
// Obtain the total minutes
long totalMinutes = totalSeconds / 60; //总分钟数
// Compute the current minute in the hour
long currentMinute = totalMinutes % 60; //当前分钟
// Obtain the total hours
long totalHours = totalMinutes / 60; //总小时数
// Compute the current hour
long currentHour = totalHours % 24;//当前小时
// Display results
System.out.println("Current time is " + currentHour + ":" + currentMinute + + currentSecond + " GMT");
}
}
result: Current time is 17:31:8 GMT