Day01 代码
String s1 = "a" + "b" + "c" ;
String s2 = "abc" ;
System. out. println ( s1 == s2) ;
System. out. println ( s1. equals ( s2) ) ;
String s1 = "ab" ; * 这里s3是变量s1与常量"c" 相连,结果是变量。因此s3, s2地址值不一样*
String s2 = "abc" ;
String s3 = s1 + "c" ;
System. out. println ( s3 == s2) ;
System. out. println ( s3. equals ( s2) ) ;
int dayNum = cal. get ( Calendar. DAY_OF_WEEK) ;
System. out. println ( dayNum) ; * -- -- 打印结果是4 (因为西方是从周日开始算)*
SimpleDateFormat sdf = new SimpleDateFormat ( "EEE" ) ;
String format = sdf. format ( dayNum) ;
System. out. println ( format) ; * -- -- 格式化打印结果是周五(格式化后的结果还是按照中国规格)*
public static void main ( String[ ] args) {
Calendar cal = Calendar. getInstance ( ) ;
cal. set ( 2018 , 2 - 1 , 14 ) ; * -- -- 要求打印出“星期几”的格式。而格式化是“周几”用EEE格式*
int dayNum = cal. get ( Calendar. DAY_OF_WEEK) ; * -- -- Calendar中月份从0 - 11. 即代表1 - 12 *
System. out. println ( getWeek ( dayNum) ) ;
}
private static String getWeek ( int dayNum) {
String[ ] arr = { "" , "星期日" , "星期一" , "星期二" , "星期三" , "星期四" , "星期五" , "星期六" } ;
return arr[ dayNum] ; * (注意上面第0 号索引处是空格,因为dayNum从1 开始。而且西方从星期日开始算)*
}
String[ ] list = { "010" , "3223" , "666" , "7890987" , "123123" } ;
int count = 0 ; * -- -- 这题是要求判断list中的字符串是否是对称的。每次for 循环*
for ( int i = 0 ; i < list. length; i++ ) { * 都new 一次,可以将里面每一个字符都反转。*
StringBuilder sb = new StringBuilder ( list[ i] ) ;
StringBuilder re = sb. reverse ( ) ;
public static void main ( String[ ] args) {
Scanner sc = new Scanner ( System. in) ;
System. out. println ( "录入你的出生日期,格式如下: 1999-3-1" ) ;
String birth = sc. nextLine ( ) ;
String[ ] split = birth. split ( "-" ) ;
int year = Integer. parseInt ( split[ 0 ] ) ; * -- -- 掌握这里的切割方法,得到年、月、日*
int month = Integer. parseInt ( split[ 1 ] ) ;
int date = Integer. parseInt ( split[ 2 ] ) ;
Calendar cal = Calendar. getInstance ( ) ;
cal. set ( year, month - 1 , date) ; * -- -- 将出生日期的年月日导入日历,进行格式化操作*
int dayNum = cal. get ( Calendar. DAY_OF_WEEK) ;
int dayYear = cal. get ( Calendar. DAY_OF_YEAR) ;
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy年MM月dd日 EEE" ) ;
Date dd = cal. getTime ( ) ; * -- -- 此处的getTime ( ) 方法是导入cal并不是求毫秒值了。*
String birthday = sdf. format ( dd) ;
StringBuilder sb = new StringBuilder ( ) ;
StringBuilder number = sb. append ( "这一年当中的第" ) . append ( dayYear) . append ( "天" ) ;
System. out. println ( birthday + number) ; * -- -- StringBuilder用于连接的体现*
}
public static void main ( String[ ] args) {
int [ ] src = new int [ ] { 1 , 2 , 3 , 4 , 5 } ;
int [ ] dest = new int [ ] { 6 , 7 , 8 , 9 , 10 } ; * -- -- arraycopy ( src, i, dest, j, l) *
System. arraycopy ( src, 0 , dest, 0 , 3 ) ; * -- -- 将src数组索引为i的数据,复制到dest数组索引为j的数*
}
今日正能量:
你的小宇宙在哪里?不爽的时候就去那里住一阵子吧!
-- -- -- Pets_zeng