为什么来自Scanner方法的nextDouble()向我发送"Exception"消息? [英] Why is nextDouble() from the Scanner method sending me "Exception"
本文介绍了为什么来自Scanner方法的nextDouble()向我发送"Exception"消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我假设输入2个数字,一个int表示要提取的金额,一个double表示余额(两个之间有一个空格).由于每次提款均收取0.5的手续费,因此余额必须加倍.那就是必须打印的内容. 我在nextDouble上收到错误,为什么?我只有1个月的编码,我认为这将是小菜一碟,我认为30年前BASIC语法毁了我:(
I'm suppose to enter 2 numbers, one int that is the amount to withdraw and one double which is the balance (with a space between them). Since every withdraw charges a fee of 0.5, balance must be a double. And thats what must be printed. I get error at nextDouble, why? I have just 1 month coding, I thought this was going to be a piece of cake, I think BASIC syntax ruined me 30 years ago :(
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//init variables
int amount;
double balance;
//insert amount and balance
Scanner input = new Scanner (System.in);
amount = input.nextInt();
balance = input.nextDouble();
//reduce amount+fee from balance
balance=balance-(amount + 0.50);
//print new balance
System.out.print(balance);
input.close();
}
}
推荐答案
它取决于语言环境,请尝试使用逗号而不是点,反之亦然.
It is dependant on Locale, try to use comma instead of a dot or vice versa.
例如: 1,5 ,而不是 1.5
这篇关于为什么来自Scanner方法的nextDouble()向我发送"Exception"消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文