带有命令行参数的Math.pow [英] Math.pow with Command line arguments

查看:62
本文介绍了带有命令行参数的Math.pow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要由用户获取给定数字的幂值(作为命令行参数)

I need to get the power value of a given number by user (as a command line argument)

这是我的代码,它带有编译错误.

This is my code and it has comes up with a compilation error.

任何人都可以帮助我吗?

Can anyone please help me ?

class SquareRoot{

      public static void main(String args []){

          double power = Math.pow(args[0]);         
          System.out.println("Your squared value is " + power);

      }
}

推荐答案

这是因为Math.pow需要两个参数.像这样:

This is because Math.pow needs two arguments. Something like:

double power = Math.pow(Double.parseDouble(args[0]),2.0);

请参见javadoc .

这篇关于带有命令行参数的Math.pow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆