小编End*_*Egg的帖子

划分(6.022/6.022 = 1000)Java时获得1000作为答案而不是1

所以,我是编程的新手,我试图制作一个基本的鼹鼠(化学)计算器只是为了好玩.我没有找到这个问题.如果有人回答,请发给我链接.

这是公式:n = N / Nawhere n = moleNa = 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 …
Run Code Online (Sandbox Code Playgroud)

java integer-division

6
推荐指数
1
解决办法
191
查看次数

Switch语句:为什么我在不同的情况下不能拥有相同的变量名?Java的

我仍然在编写代码,它在像我这样的项目中没有产生很大的不同,但如果我要做更大的事情,那将是一种痛苦.这里是:

        case 0:
            System.out.print("Insert the N: ");
            double N = in.nextDouble();
            double mol = N / Na;
            System.out.print("There are " + mol + " mol in that sample");
            break;

        case 1:
            System.out.print("Insert the m: ");
            double m = in.nextDouble();
            System.out.print("Insert the M: ");
            double M = in.nextDouble();
            double mol = m / M;
            System.out.print("There are " + mol + " mol in that sample");
            break;

        case 2:
            System.out.print("Insert the V: ");
            double V = in.nextDouble();
            double mol = V / …
Run Code Online (Sandbox Code Playgroud)

java duplicates switch-statement

6
推荐指数
1
解决办法
2792
查看次数

如何在C中显示没有小数位的浮点数

我想打印一个没有十进制数字的浮点数.我知道我可以使用另一个像int这样的变量并使其相同,但我想避免这种情况更简单(如%02f但限制而不是至少两位数).

如果没有办法,那么我将使用变量int.

谢谢

c

-2
推荐指数
1
解决办法
1386
查看次数

标签 统计

java ×2

c ×1

duplicates ×1

integer-division ×1

switch-statement ×1