所以,我是编程新手,我试图制造一个基本的摩尔(化学)计算器只是为了好玩。我没有找到这个问题。如果有人回答,请给我链接。分割时得到1000而不是1(6.022/6.022 = 1000)Java
这是下式:其中n = N/Na
和n = mole
Na = 6.022E23
代码的第一部分引发错误。只是试图得到一个,用我的N分割Na,甚至用6.022而不是6.022E23,我得到1000.0作为答案。
Scanner in = new Scanner(System.in);
double Na = 6.022;
System.out.print("What do you want to know? Mol(0) or N(1)? ");
int first = in.nextInt();
if (first == 0){
System.out.print("Insert N: ");
double N = in.nextDouble();
double mol = N/Na;
System.out.print("There are " + mol + " mol in that sample.");
}
else if (first == 1){
System.out.print("Insert mol: ");
double mol = in.nextDouble();
double N = mol*Na;
System.out.print("There are " + N + " molecules, atoms or ions in that sample.");
}
输出0:
What do you want to know? Mol(0) or N(1)? 0
Insert N: 6.022
There are 1000.0 mol in that sample.
输出1:
What do you want to know? Mol(0) or N(1)? 1
Insert mol: 1
There are 6.022 molecules, atoms or ions in that sample.
预先感谢。
看起来像'Locale'问题。你正在使用什么'Locale'? – Keppil
@Keppil这就是我所期望的。在美国的系统中,点被解释为数千的分隔符,而不是小数点。 –
@Keppil我不知道。新来的,从来没有听说过这个词。我想我明白你的意思了。不,这不是问题。我可以用点和逗号工作,都是一样的。但1000不是任何地方。 – EnderEgg