关于java的一些碎碎念

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修饰符默认为包内所有类可以访问当前类。又称默认包内友好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值