相关疑难解决方法(0)

^运算符在Java中做了什么?

请问有什么功能^(尖)运算的Java服务?

当我尝试这个:

int a = 5^n;
Run Code Online (Sandbox Code Playgroud)

......它给了我:

对于n = 5,
对于n = 4 返回0 ,
对于n = 6 返回1 ,返回3

...所以我猜它不会执行取幂.但那又是什么呢?

java operators exponentiation

276
推荐指数
13
解决办法
40万
查看次数

在Java中将数字提升到一个幂

这是我的代码.由于某种原因,我的BMI计算不正确.当我在计算器上检查输出时:(10/((10/100)^2)))我得到1000,但在我的程序中,我得到5.我不确定我做错了什么.这是我的代码:

import javax.swing.*;

public class BMI {
    public static void main(String args[]) {
        int height;
        int weight;
        String getweight;
        getweight = JOptionPane.showInputDialog(null, "Please enter your weight in Kilograms");
        String getheight;
        getheight = JOptionPane.showInputDialog(null, "Please enter your height in Centimeters");
        weight = Integer.parseInt(getweight);
        height = Integer.parseInt(getheight);
        double bmi;
        bmi = (weight/((height/100)^2));
        JOptionPane.showMessageDialog(null, "Your BMI is: " + bmi);
    }
}
Run Code Online (Sandbox Code Playgroud)

java

63
推荐指数
4
解决办法
35万
查看次数

标签 统计

java ×2

exponentiation ×1

operators ×1