首页 > 编程知识 正文

java int最大值,int对应的输出为%d

时间:2023-05-04 20:08:20 阅读:111393 作者:3016

int nextInt () )

说明(Description )

java.util.Scanner.nextInt )方法将输入的下一个标签作为int进行扫描。 对此方法nextInt () (的调用与对nextInt ) (radix )的调用完全相同。 其中radix是此扫描仪的默认基数。

声明(Declaration )

以下是java.util.Scanner.nextInt ()方法的声明public int nextInt ) )

参数(Parameters )。

NA

返回值)。

此方法返回从输入中扫描的int

异常(exception (inputmismatchexception ) -如果以下标记与Integer正则表达式不匹配或超出范围

NoSuchElementException -如果没有输入

IllegalStateException -如果此扫描仪已关闭

示例(Example ) )。

以下示例说明如何使用java.util.Scanner.nextInt ()方法。 package com.iowiki;

import java.util.*;

公共类扫描仪demo {

publicstaticvoidmain (字符串[ ] args ) {

String s='Hello World! 3 3.0=6.0 true ';

//createanewscannerwiththespecifiedstringobject

scannerscanner=newscanner(s );

//findthenextinttokenandprintit

//loop for the whole scanner

wile(Scanner.Hasnext () ) ) ) )。

//if the next is a int,print found and the int

(scanner.hasnext int () ) ) ) )。

system.out.println (' found : ' scanner.nextint ) );

}

//if no int is found,print ' not found : ' and the token

system.out.println (' not found : ' scanner.next ) );

}

//close the scanner

scanner.close (;

}

}

试着编译并运行上述程序。 这将产生以下结果-Not Found :Hello

not found :世界!

Found :3

Not Found :

Not Found :3.0

Not Found :=

Not Found :6.0

非福特: true

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。