如题!
当
int a=scanner.nextint(5);
在控制台里不能输入大于5的数,
当
int a=scanner.nextint(100);
在控制台里输入数会报超出范围的错误;
请教这参数是什么作用????
------解决方案--------------------
/**
* Scans the next token of the input as an <tt>int</tt>.
* This method will throw <code>InputMismatchException</code>
* if the next token cannot be translated into a valid int value as
* described below. If the translation is successful, the scanner advances
* past the input that matched.
*
* <p> If the next token matches the <a
* href="#Integer-regex"><i>Integer</i></a> regular expression defined
* above then the token is converted into an <tt>int</tt> value as if by
* removing all locale specific prefixes, group separators, and locale
* specific suffixes, then mapping non-ASCII digits into ASCII
* digits via {@link Character#digit Character.digit}, prepending a
* negative sign (-) if the locale specific negative prefixes and suffixes
* were present, and passing the resulting string to
* {@link Integer#parseInt(String, int) Integer.parseInt} with the
* specified radix.
*
* @param radix the radix used to interpret the token as an int value
* @return the <tt>int</tt> scanned from the input
* @throws InputMismatchException
* if the next token does not match the <i>Integer</i>
* regular expression, or is out of range
* @throws NoSuchElementException if input is exhausted
* @throws IllegalStateException if this scanner is closed
*/
public int nextInt(int radix)
看看注释,那个参数是radix 也就是进制。 123 , 0xfff 之类的,而不是你说的最大多少
------解决方案--------------------
26个英文字母 + 10个数字 猜猜等于多少。
如果你想实现个37进制,那么就要引入其他的字符了。