日志的Java对数(num,base)(已关闭)

时间:2013-12-27 09:44:56

标签: java android math logarithm

我正在用android SDK(Java)创建一个程序,但我已经为我的程序设计了一个数字,然后是基础。基数可以是任意数字。除了无限切换外壳,我还有办法吗? (我已经关闭了这个帖子。我发现logb(x)= log10(x)/ log10(b))

2 个答案:

答案 0 :(得分:6)

这是数学可以帮助解决问题的地方;)

enter image description here

这允许您计算任何基数的日志。

public static double log(double value, double base) {
    return Math.log(value)/Math.log(base);
}

答案 1 :(得分:0)

我不确定你的问题是什么,

但是你可以在按下按钮后直接获得价值(不需要开关/箱子)

Button   mButton;
EditText base,num;
int iBase,iNum;

/** Called activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mButton = (Button)findViewById(R.id.button);
    base   = (EditText)findViewById(R.id.edittext_base);
    num    = (EditText)findViewById(R.id.edittext_num);

    mButton.setOnClickListener(
        new View.OnClickListener()
        {
            public void onClick(View view)
            {
                iNum = Integer.parseInt(num.getText().toString());
                iBase = Integer.parseInt(base.getText().toString());
                Log.v("Result", Math.Log(iNum)/Math.Log("iBase"));
            }
        });
}