1. java函数不需要事先声明,在调用前后定义都可,很舒服
2. java没有while(1),只有while(true), 前者报错信息为无法将int类型转化为boolean类型
3. vscode实现自动格式化代码补全空格的方法是Editor.formatOnType = true;
4. Scanner 类关于读取输入的next(), nextLine(), nextInt(), nextDouble()...区分 btw hasNextXX()同理
nextInt(): it only reads the int value, nextInt() places the cursor in the same line after reading the input.
只读取整数类型数据, nextInt()在读取完输入后把光标放在读取数据的同一行,该数据的后面。
'''
next(): read the input only till the space. It can't read two words separated by space. Also, next() places thecursor in the same line after reading the input.
只读取到空格,不能读取被空格分开的两个单词(也就是不能读取空格),并且在读取完后把光标放在读取数据的同一行,该数据的后面。(同上)
nextLine(): reads input including space between the words (that is, it reads till the end of line \n). Once the input is read, nextLine() positions thecursor in the next line.
读取整行的数据包括单词间的空格,到回车结束(也就是从开始读一整行包括回车),读取结束后,光标放在下一行开头。
所以上面一题的原因:nextInt()只读取了数值2,剩下"\n"还没有读取,并将光标放在本行中2后面。接着nextLine()会读取"\n",并结束本次读取。
————————————————
版权声明:本文为CSDN博主「大帅_Sun」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_32561655/article/details/62892427
'''
5. 比较字符串相等不能用“==”,这是比较引用是否相同的。应该用a.equals(b) 若字符串相等返回true。
6. Java 类不写public private protected修饰符默认为包内所有类可以访问当前类。又称默认包内友好。