随笔分类 -  Java基础

摘要:1.ip public class TestInetAddress { public static void main(String[] args) { try { //查询本机IP,可以new InetAddress byName = InetAddress.getByName("localhos 阅读全文
posted @ 2021-05-29 11:17 Henry` 阅读(132) 评论(0) 推荐(0)
摘要:supper: 1. super调用父类的构造方法,必须在子类构造方法的第一个 2. super必须只能出现在子类的方法或者子类构造方法中 3. super()和this()不能同时调用构造方法,因为必须要在第一个 vs this: 1. 代表的对象不同 this:本身调用者这个对象 super代表 阅读全文
posted @ 2021-05-27 09:17 Henry` 阅读(59) 评论(0) 推荐(0)
摘要:public class ArrayTest { public static void main(String[] args) { int[][] array1 = new int[11][11]; array1[1][2] = 1; array1[2][3] = 2; array1[4][5] = 阅读全文
posted @ 2021-05-26 20:51 Henry` 阅读(28) 评论(0) 推荐(0)
摘要:public class BubbleSortTest { public static void main(String[] args) { int[] arrays = {1,5,3,4,7,8,6,12}; int[] ints = bubbleSort(arrays); System.out. 阅读全文
posted @ 2021-05-26 19:21 Henry` 阅读(48) 评论(0) 推荐(0)
摘要:其长度是确定的。数组一旦被创建,它的大小就是不可以改变的。 其元素必须是相同类型,不允许出现混合类型。 数组中的元素可以是任何类型,包括基本类型和引用类型。 数组变量属引用类型,数组也可以看成是对象,数组中的每个元素相当于该对象的成员变量。数组本身就是对象,Java中对象是在堆中的,因此数组无论保存 阅读全文
posted @ 2021-05-25 20:50 Henry` 阅读(167) 评论(0) 推荐(0)
摘要:public class TestDemo { public static void main(String[] args) { //打印正三角形 for (int i = 1; i <= 5; i++) {![](https://img2020.cnblogs.com/blog/2406104/2 阅读全文
posted @ 2021-05-24 23:02 Henry` 阅读(200) 评论(0) 推荐(0)
摘要:public class ForDemo2 { public static void main(String[] args) { for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(i+ "*" 阅读全文
posted @ 2021-05-24 21:48 Henry` 阅读(43) 评论(0) 推荐(0)
摘要:public class ForDemo1 { public static void main(String[] args) { //用while或for循环输出1-1000之间能被5整除的数,并且每行输出4个 for (int i = 0; i <= 1000; i++) { if (i%5==0 阅读全文
posted @ 2021-05-24 21:19 Henry` 阅读(439) 评论(0) 推荐(0)
摘要:public class ForDemo { public static void main(String[] args) { //计算0-100之间的奇数和偶数的和 int oddSum = 0; int evenSum = 0; for (int i = 0; i < 100; i++) { i 阅读全文
posted @ 2021-05-24 21:03 Henry` 阅读(412) 评论(0) 推荐(0)
摘要:public class Demo{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); double sum = 0;//和 int num = 0;//输入多少个数字 while(sc 阅读全文
posted @ 2021-05-24 20:16 Henry` 阅读(78) 评论(0) 推荐(0)
摘要:next() 一定要读取到有效字符后才可以结束输入 对输入有效字符之前遇到的空白,next()方法会自动将其去掉 只有输入有效字符后才将其后面输入的空白作为分隔符或者结束符 next()不能得到带有空格的字符串 nextLine() 以Enter为结束符,也就是说nextLine()方法返回的是输入 阅读全文
posted @ 2021-05-24 19:53 Henry` 阅读(105) 评论(0) 推荐(0)
摘要:![](https://img2020.cnblogs.com/blog/2406104/202105/2406104-20210524193117908-995452630.png) ![](https://img2020.cnblogs.com/blog/2406104/202105/2406104-20210524193135586-1887335792.png) ![](https://i 阅读全文
posted @ 2021-05-24 19:35 Henry` 阅读(62) 评论(0) 推荐(0)
摘要:int a = 5; boolean b = (a<4)&&(a++<4); System.out.println(b);false,因为a<4已经是false,所以a++<4不会执行 System.out.println(a);//a = 5 阅读全文
posted @ 2021-05-24 10:13 Henry` 阅读(108) 评论(0) 推荐(0)
摘要:public class Demo{ public static void main(String[] args){ //++ -- 自增,自减 一元运算 int a = 4; int b = a++; int c = ++a; System.out.println("a="a);//a=6 Sys 阅读全文
posted @ 2021-05-24 09:50 Henry` 阅读(65) 评论(0) 推荐(0)
摘要:所有变量、方法、类名:见名知意 类成员变量:首字母小写和驼峰原则:monthSalary 除了第一个单词以外,后面的单词首字母大写 lastName 局部变量:首字母小写和驼峰原则 常量:大写字母和下划线:MAX_VALUE 类名:首字母大写和驼峰原则:Man,GoodMan 方法名:首字母小写和驼 阅读全文
posted @ 2021-05-24 09:15 Henry` 阅读(141) 评论(0) 推荐(0)
摘要:类型转换 由于java是强类型语言,所以要进行有些运算的时候,需要用到类型转换。 低 高 byte,short,char > int > long > float > double 运算中,不同类型的数据先转化为同一类型,然后进行计算。 int i = 128; byte j = (byte)i;/ 阅读全文
posted @ 2021-05-23 23:11 Henry` 阅读(69) 评论(0) 推荐(0)