Java语言用户输入错误与导入文件
我面临这个问题,我的代码没有错误。这是代码。请记住,请记住我在Android Studio上写Java,因为我正在从事应用程序开发。
练习.java
package com.example.javastart;
import java.util.Scanner;
public class practice {
public static void main(String[] args) {
System.out.println("Taking Input");
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number for Table ");
int a = sc.nextInt();
for (int i = 1; i <= 10; i++) {
int total = a * i;
System.out.println(a + " * "+ i + " = "+ total);
}
}
}
这是一些错误
Task :javastart:practice.main() FAILED
Taking Input
Enter Number for Table
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at com.example.javastart.practice.main(practice.java:9)
Execution failed for task ':javastart:practice.main()'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nosuchelementException
如果没有更多令牌,将抛出。这是由调用nextInt()
而无需检查是否可用的整数引起的。尝试使用hasnextint()在调用nextint()
之前检查是否有任何令牌。NoSuchElementException
will be thrown if no more tokens are available. This is caused by invokingnextInt()
without checking if there's any integer available. Try using hasNextInt() to check if any tokens are available before callingnextInt()
.