计算土星和木星的重量

时间:2014-05-06 11:15:21

标签: java

我有这段代码

public class Operator {

    public static void main(String[] args) {

        //This part of the code is about my weight on earth.
        System.out.print("My weight on earth is ");
        double mWOE = 66.2;

        //mWOE = myWheightOnEarth
        System.out.println(mWOE);

        //This part of the code is about my weight on jupiter.
        System.out.print("My weight on jupiter is ");
        double mWOJ = mWOE * 2.54;

        //mWOJ = myWheightOnJupiter
        System.out.println(mWOJ);

        //This part of the code is about my wheight on saturn
        System.out.print("My weight on saturn is ");
        double mWOS = mWOE * 1.08;

        //mWOS = myWheightOnSaturn
        System.out.println(mWOS);
    }

}

我想让我的程序得到重量并对土星和木星施加重量。我该怎么做代码?

P.S:这是在java。

1 个答案:

答案 0 :(得分:1)

如果您想从键盘获取输入,请使用Scanner课程。试试这个:

System.out.print("My weight on earth is ");
Scanner s = new Scanner(System.in);
double mWOE = 0.0;
if (s.hasNextDouble()){
    mWOE = s.nextDouble();
}

然后,剩下的代码是相同的。