java - 在任何 IDE 中运行脚本但在 replit 中运行脚本的问题不存在任何问题——JAVA
问题描述
我是 Java 新手,脚本的这个试用版在 replit.com 中运行,但另一个 IDE 没有运行。为什么?我看不出问题。你能帮我吗?非常感谢
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k, n, cpeso;
System.out.print("change: ");
k = sc.nextInt();
while (k > 100 || k<0){
System.out.println("input the correct number :" );
k = sc.nextInt();
}
System.out.print("dollars: ");
n = sc.nextInt();
while (n > 10000 || n<0){
System.out.println("input the correct number :" );
n = sc.nextInt();
}
if(n<=10000 && n>=0 && k<=100 && k>=0){
cpeso = n * k;
System.out.println(n+" dollars equivalent to "+cpeso+" pesos");
}else {
}
}
}
Netbeans、paiza.io 等 IDE 中的错误是:
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 Main.main(Main.java:9)
解决方案
推荐阅读
- c++ - 欧拉计划 23 C++
- python - SystemExit:python google colab中的2个无法识别的参数
- django - Django rest 框架 api 测试返回空结果
- svelte - 苗条工兵 - onMount 不触发
- java - 如何等到属性具有不同的值?
- javascript - 如何在一个函数中返回两个函数,该函数在反应中呈现为两个组件,而不是第二个函数覆盖第一个函数
- laravel - 我如何从 laravel 中的两个表中获取记录或如何将日期与第二个表匹配
- python - 高效的递归迭代器:可能吗?
- flutter - Flutter - 当列表向下滚动时显示一个浮动小部件
- wordpress - 您的网站出现严重错误。了解有关在 WordPress 中调试的更多信息