1、 next()和nextLine()的区别:
nextLine()返回的是Enter之前所有字符,可以得到带有空格的字符串
next()会自动消去有效字符前的空格,只返回输入的字符,不能得到带空格的字符串
注:
nextLine()不能用于nextInt()等方法后面,解决方法有两种:
(1)在每一个next()、nextInt()等方法后面加一个nextLine()语句,将被next()去掉的Enter结束符过滤掉;
(2)将nextLine()改为next()
2、输出换行的方法
需要用System.out.println()的方法来换行。
在使用换行时,使用System.out.print("\n"),或者System.out.printf("%f\n",x)时,都会给出Presentation Error的提示
3、Character类的使用
Character类提供了许多方法,可以使我们的代码变得精简。下面,我列举几个常用的方法:
(1)digit(char ch,int radix) //返回使用指定基数的字符ch的数值
(2)isDigit(int c) //确定字符是否为数字
(3)isLetter(char ch) //确定字符是否为字母
(4)isLetterOrDigit(char ch) //确定字符ch是否为字母或者数字
(5)isLowerCase(char ch) //确定字符ch是否为小写字母
(6)isUpperCase(char ch) //确定字符ch是否为大写字母
(7)toLowerCase(char ch)//将字符转换为小写
(8)toUpperCase(char ch)//将字符转换为大写