Java 双重和'^';接线员,不可能吗?

Java 双重和'^';接线员,不可能吗?,java,android,operators,double,Java,Android,Operators,Double,我是新来这里的(确切地说是5天大)用Android和Java制作基本程序。下面是我正在编写的代码,我被困在sendAmount()上的“else if”部分 我在那里得到了一个错误,上面写着“参数类型double,double的运算符^未定义” 现在我的问题是,如何让它工作并显示结果 private EditText entPrinAmt; private EditText entIntRate; private EditText entTol; private EditText entMonA

我是新来这里的(确切地说是5天大)用Android和Java制作基本程序。下面是我正在编写的代码,我被困在sendAmount()上的“else if”部分

我在那里得到了一个错误,上面写着“参数类型double,double的运算符^未定义”

现在我的问题是,如何让它工作并显示结果

private EditText entPrinAmt;
private EditText entIntRate;
private EditText entTol;
private EditText entMonAmt;

private TextView txtFactor;
private TextView txtFutValue;
private TextView txtIntIncome;
private TextView txtEffRate;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    entPrinAmt = (EditText) findViewById(R.id.ent_prin_amt);
    entIntRate = (EditText) findViewById(R.id.ent_int_rate);
    entTol = (EditText) findViewById(R.id.ent_tol);
    entMonAmt = (EditText) findViewById(R.id.ent_mon_amt);

    txtFactor = (TextView) findViewById(R.id.txtFactor);
    txtFutValue = (TextView) findViewById(R.id.txtFutureVal);
    txtIntIncome = (TextView) findViewById(R.id.txtIntIncome);
    txtEffRate = (TextView) findViewById(R.id.txtEffRate);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void sendAmount(View view) {

    DecimalFormat df = new DecimalFormat("#,###,###,###,###,###.##");
    DecimalFormat factorFormat = new DecimalFormat("#,###.#####################");

    double dPA = Double.parseDouble(entPrinAmt.getText().toString());
    double dIR = Double.parseDouble(entIntRate.getText().toString());
    double dTL = Double.parseDouble(entTol.getText().toString());
    double dMA = Double.parseDouble(entMonAmt.getText().toString());

    if (dPA < 0){
        Context context = getApplicationContext();
        CharSequence txtToast = "Must not be negative!";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, txtToast, duration);
        toast.show();
    }
    else if (dPA == 0 && dIR>0 && dTL>0 && dMA>0){
        Double resultPA;
        resultPA = ((dMA * ((1+dIR/12)^dTL-1)/((1+dIR/12)^dTL*dIR/12)),2);

        /*String f = df.format(resultPA);  <-v-DO NOT MIND THIS
        txtFactor.setText("Principal Amount: P" + f);*/
    }
    else {
        Context context = getApplicationContext();
        CharSequence txtToast = "Can't Compute Principal Amount!";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, txtToast, duration);
        toast.show();
    }
}
private EditText entPrinAmt;
私有编辑文本中心;
私人编辑文本;
私有编辑文本;
私有文本视图txtFactor;
私有文本视图txtFutValue;
私有文本视图txtinincome;
私有文本视图txtEffRate;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
entPrinAmt=(EditText)findViewById(R.id.ent\u prin\u amt);
Ententrate=(EditText)findViewById(R.id.ent\u int\u rate);
entTol=(EditText)findViewById(R.id.ent\u tol);
entMonAmt=(EditText)findViewById(R.id.ent\u mon\u amt);
txtFactor=(TextView)findViewById(R.id.txtFactor);
txtFutValue=(TextView)findViewById(R.id.txtFutureVal);
txtinincome=(TextView)findViewById(R.id.txtinincome);
txtEffRate=(TextView)findViewById(R.id.txtEffRate);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
公共作废发送金额(查看){
DecimalFormat df=新的DecimalFormat(“#,#,#,#,#,#,#,#,#,#,#,#,#”);
DecimalFormat factorFormat=新的DecimalFormat(“#、#、#、#、#、#”;
double dPA=double.parseDouble(entPrinAmt.getText().toString());
double dIR=double.parseDouble(entIntRate.getText().toString());
double dTL=double.parseDouble(entTol.getText().toString());
double dMA=double.parseDouble(entMonAmt.getText().toString());
如果(dPA<0){
Context=getApplicationContext();
CharSequence txtToast=“不得为负!”;
int duration=Toast.LENGTH\u SHORT;
Toast Toast=Toast.makeText(上下文、txtToast、持续时间);
toast.show();
}
否则如果(dPA==0&&dIR>0&&dTL>0&&dMA>0){
双重结果;
结果PA=((dMA*((1+dIR/12)^dTL-1)/(1+dIR/12)^dTL*dIR/12)),2);

/*字符串f=df.format(resultPA);
^
是一种按位异或运算,很可能您希望

double d = Math.pow(a, b); // a^^b 

^
运算符是按位异或,而不是幂。事实上,Java没有定义幂运算符。您应该改为使用


此外,在使用货币时,您应该使用,原因如下。

使用pow函数

double output = Math.pow(x,y);

是的,在java中,参数类型double、double的运算符^(按位异或)未定义。 使用
Math.pow(double,double)
而不是
^

因此,您的代码将如下所示:

resultPA = ((dMA * (Math.pow((1+dIR/12),dTL-1))/(Math.pow((1+dIR/12),dTL)*dIR/12)),2);

哦,谢谢你!但是现在我在这方面犯了一个错误。上面说“作业的左边必须是一个变量”。不客气,但你已经选择了答案!请提出一个新问题,而不是在评论中。我真的认为这是一种力量。我今天学到了一些东西,谢谢。