首页 技术 正文
技术 2022年11月8日
0 收藏 941 点赞 1,927 浏览 3387 个字
  •     JDK :OpenJDK-11
  •      OS :CentOS 7.6.1810
  •      IDE :Eclipse 2019‑03
  • typesetting :Markdown

code

package per.jizuiku.base;import java.util.Scanner;/**
* @author 给最苦
* @date 2019/06/29
* @blog www.cnblogs.com/jizuiku
*/
class Demo { /**
* @param args
*/
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个数据");
int x = sc.nextInt();
System.out.println("你所输入的数据是:" + x); sc.close();
}
}

result

请输入一个数据
55
你所输入的数据是:55

sourceCode

/**
* Constructs a new {@code Scanner} that produces values scanned
* from the specified input stream. Bytes from the stream are converted
* into characters using the underlying platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
*
* @param source An input stream to be scanned
*/
public Scanner(InputStream source) {
this(new InputStreamReader(source), WHITESPACE_PATTERN);
}
/**
* Scans the next token of the input as an {@code int}.
*
* <p> An invocation of this method of the form
* {@code nextInt()} behaves in exactly the same way as the
* invocation {@code nextInt(radix)}, where {@code radix}
* is the default radix of this scanner.
*
* @return the {@code int} 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() {
return nextInt(defaultRadix);
}
/**
* Scans the next token of the input as an {@code int}.
* This method will throw {@code InputMismatchException}
* 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 {@code int} 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.
*
* <p>If the radix is less than {@link Character#MIN_RADIX Character.MIN_RADIX}
* or greater than {@link Character#MAX_RADIX Character.MAX_RADIX}, then an
* {@code IllegalArgumentException} is thrown.
*
* @param radix the radix used to interpret the token as an int value
* @return the {@code int} 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
* @throws IllegalArgumentException if the radix is out of range
*/
public int nextInt(int radix) {
// Check cached result
if ((typeCache != null) && (typeCache instanceof Integer)
&& this.radix == radix) {
int val = ((Integer)typeCache).intValue();
useTypeCache();
return val;
}
setRadix(radix);
clearCaches();
// Search for next int
try {
String s = next(integerPattern());
if (matcher.group(SIMPLE_GROUP_INDEX) == null)
s = processIntegerToken(s);
return Integer.parseInt(s, radix);
} catch (NumberFormatException nfe) {
position = matcher.start(); // don't skip bad token
throw new InputMismatchException(nfe.getMessage());
}
}

resource

  • [ JDK ] openjdk.java.net
  • [ doc – 参考 ] docs.oracle.com/en/java/javase/11
  • [ 规范 – 推荐 ] yq.aliyun.com/articles/69327
  • [ 规范 – 推荐 ] google.github.io/styleguide
  • [ 源码 ] hg.openjdk.java.net
  • [ OS ] www.centos.org
  • [ IDE ] www.eclipse.org/downloads/packages
  • [ 平台 ] www.cnblogs.com


感谢帮助过 给最苦 的人们。

Java、Groovy和Scala等基于JVM的语言,优秀,值得学习。

规范的命名和代码格式等,有助于沟通和理解。

JVM的配置、监控与优化,比较实用,值得学习。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297