首页 > 解决方案 > 在任何 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)

标签: java

解决方案


推荐阅读