2021/3/29-[DAY1]Records<=Java Tutorial for Beginners [2020]

Multi-Dimensional Arrays

int [][]numbers = {{1,2,3},{4,5,6}} ;
//each row is array itself,because it's a list of items
System.out.println(Arrays.deepToString(numbers));
result

[[1, 2, 3], [4, 5, 6]]

Constants

final float PI = 3.14F;
//use all capitalized letter to name const

Arithmetic Experssions

int x = 1;
int y = x++;
System.out.println(x);
System.out.println(y);

result
2
1

Casting

//Q:how many bytes do we have in a short variable?
 /*A:we have 2 bytes in a short variable.*/
//Q:how many bytes do we have in a integer variable?
/*A:we have 4 bytes in a short variable.*/
/*so any value we stored in a short variable
 can also be stored in a integer varible.
 */
//1.Implicit casting
//there is no chance for data to lose
//byte => short => int => long => float => double
//2.Explicit casting
Integer.parseInt(String s);
Short.parseShort(String s);
Float.parseFloat(String s);
//An example
String x = "1";
int y = Integer.parseInt(x) + 2;
System.out.println(y);
result

3

//why this matters?
/*almost always we get values as Strings*/
//Another example
String x = "1.1";
double y = Double.parseDouble(x) + 2;
System.out.println(y);
result

3.1

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容