目前JAVA 才学到基本程序设计,看着老师的直播录像加自己pdf(小声BB,pdf看久了真的眼睛酸)。由于才转到软工,还剩4大节课没补上。需要加快速度了。
由于在做其他的作业,今天花费的时间不是很多。
大部分看的和c语言中的类似,就不一一详述
主要讲讲自己学到的新东西
(有图片的上传太大了,调不到就略了)
例如1.23456*102
== 1.23456E2 或者1.23456E+2 (E 或者e表示指数)
显示时间的小程序通过调用System.currentTimeMillis()返回当前时间。
(该方法是返回从GMT1970年1月1日0时到现在当前的毫秒数,返回的是0区的时间,所以不是中国时间= =
代码基本上和书上差不多)
public static void main(String[] args){
/*先获取时间(获取的为毫秒milliseconds)
* milliseconds / 1000 obtain the totalseconds
* totalseconds % 60 obtain current seconds in the minute in the hour
* totalseconds / 60 obtain totalminute
* totalminute % 60 obtain the currten minute in the hour
* totalminute / 60 obtain the totalhour
* totalhour %24 obtain the currten hour
* */
//obtain the total milliseconds since midnight ,jan 1, 1970
long totalMilliseconds = System.currentTimeMillis();//定义一个长整型 = GMT时间
//Obtain the total seconds since midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;
//Computer the current second in the minute in the hour
long currentSeconds = totalSeconds % 60;
//Obetain the total minutes
long totalMinutes = totalSeconds / 60;
//obtain the currentMinutes
long currentMinutes = totalMinutes % 60;
//obtain the totalhours
long totalHours = totalMinutes / 60;
//obtain the currentHours
long currentHours = totalHours % 24;
//display results
System.out.println("Current time is:" + currentHours + ":" + currentMinutes + ":" + currentSeconds );
System.out.println(totalMilliseconds);
显示的是0时区的时间
中国在东8区。
强制转换在Java中
short i = 2;
i = i + 1;//这是错误的,会报错
System.out.println(i);
上面因为i是short ,下面i = i + 1;
中,i默认的是int类型
所以改为i =(int) (i+1);
就是正确
但是i += 1;
这种写法就不会报错
short i = 2;
i *= 0.1;
System.out.println(i);
这里i输出的是0
因为i =(int) (i * 0.1)