当前位置: 首页 > 知识库问答 >
问题:

JAVA错误:线程“main”JAVA.util.NoSuChelementException中的执行

高嘉树
2023-03-14

我这里有代码

public class Characterattackspeed{

public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    double base;
    double bonus;
    double current;
    int level;
    
    System.out.println("Enter the base attack speed: ");
    base = in.nextDouble();
    System.out.println("Enter the bonus attack speed %: ");
    bonus = in.nextDouble();
    System.out.println("Enter the level: ");
    level = in.nextInt();
    
    bonus = bonus / 100;
    current = base * (1 + (bonus * (level - 1)));
    
    System.out.printf("current attack speed is %.3f.", current);
    
    
    }
    
}

共有1个答案

萧鹏云
2023-03-14

有了正确的导入,它就会运行(在这里测试和运行正常):

import java.util.Scanner;

import static java.lang.System.*;

public class Characterattackspeed {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        double base;
        double bonus;
        double current;
        int level;

        out.println("Enter the base attack speed: ");
        base = in.nextDouble();
        out.println("Enter the bonus attack speed %: ");
        bonus = in.nextDouble();
        out.println("Enter the level: ");
        level = in.nextInt();

        bonus = bonus / 100;
        current = base * (1 + (bonus * (level - 1)));

        out.printf("current attack speed is %.3f.", current);


    }

}

输出示例:

Enter the base attack speed: 
12
Enter the bonus attack speed %: 
12
Enter the level: 
1
current attack speed is 12,000.
Process finished with exit code 0

您可能希望增强代码以使用方法和对象,但这不是最初的问题。

 类似资料: