Im, делающий научный калькулятор, и я хочу использовать функцию питания, но он дает неправильный ответ, например, когда я вхожу, позволяет сказать 2 как первое значение, а затем 3 в секунду, которое он дает мне 27, а не 8 его расстраивает, пожалуйста, помогите это код для кнопки питания в операторе переключателя: Обратите внимание, что первое значение, кроме как это до переключателя заявлениеMath.pow (X, Y) java
ОК здесь полный код
package com.example.scienteficcalc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
num =(TextView)findViewById(R.id.etnum);
bsin=(Button)findViewById(R.id.bsin);
bcos=(Button)findViewById(R.id.bcos);
btan=(Button)findViewById(R.id.btan);
bsec=(Button)findViewById(R.id.bsec);
bcsc=(Button)findViewById(R.id.bcsc);
bcot=(Button)findViewById(R.id.bcot);
bln=(Button)findViewById(R.id.bln);
blog=(Button)findViewById(R.id.blog);
bpwr=(Button)findViewById(R.id.bpwr);
broot=(Button)findViewById(R.id.broot);
bmod=(Button)findViewById(R.id.bmod);
one=(Button)findViewById(R.id.b1);
two=(Button)findViewById(R.id.b2);
three=(Button)findViewById(R.id.b3);
four=(Button)findViewById(R.id.b4);
five=(Button)findViewById(R.id.b5);
six=(Button)findViewById(R.id.b6);
seven=(Button)findViewById(R.id.b7);
eight=(Button)findViewById(R.id.b8);
nine=(Button)findViewById(R.id.b9);
zero=(Button)findViewById(R.id.b0);
equal=(Button)findViewById(R.id.bequal);
clear=(Button)findViewById(R.id.bc);
bsin.setOnClickListener(this);
bcos.setOnClickListener(this);
btan.setOnClickListener(this);
bsec.setOnClickListener(this);
bcsc.setOnClickListener(this);
bcot.setOnClickListener(this);
bln.setOnClickListener(this);
blog.setOnClickListener(this);
bpwr.setOnClickListener(this);
broot.setOnClickListener(this);
bmod.setOnClickListener(this);
//numbers
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
four.setOnClickListener(this);
five.setOnClickListener(this);
six.setOnClickListener(this);
seven.setOnClickListener(this);
eight.setOnClickListener(this);
nine.setOnClickListener(this);
zero.setOnClickListener(this);
equal.setOnClickListener(this);
clear.setOnClickListener(this);
}
@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;
}
@Override
public void onClick(View v) {
if(v.equals(one))
num.setText(num.getText()+""+one.getText());
if(v.equals(two))
num.setText(num.getText()+""+two.getText());
if(v.equals(three))
num.setText(num.getText()+""+three.getText());
if(v.equals(four))
num.setText(num.getText()+""+four.getText());
if(v.equals(five))
num.setText(num.getText()+""+five.getText());
if(v.equals(six))
num.setText(num.getText()+""+six.getText());
if(v.equals(seven))
num.setText(num.getText()+""+seven.getText());
if(v.equals(eight))
num.setText(num.getText()+""+eight.getText());
if(v.equals(nine))
num.setText(num.getText()+""+nine.getText());
if(v.equals(zero))
num.setText(num.getText()+""+zero.getText());
/*if(v.equals(clear))
num.setText("0");*/
input = Double.valueOf(num.getText().toString());
switch(v.getId())
{
case R.id.bsin:
output= Math.sin(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bcos:
output= Math.cos(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.btan:
output= Math.tan(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bcsc:
output= 1/Math.sin(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bsec:
output= 1/Math.cos(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bcot:
output= 1/ Math.tan(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.blog:
output = Math.log(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bln:
output = 2.30258*Math.log(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bpwr:
num.setText("");
equal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
input2= Double.valueOf(num.getText().toString());
output = Math.pow(input, input2);
answer=String.valueOf(output);
num.setText(answer);
}
});
break;
case R.id.broot:
output= Math.sqrt(input);
answer=String.valueOf(output);
num.setText(answer);
break;
case R.id.bc:
Intent intent = getIntent();
finish();
startActivity(intent);
break;
}
}
'Math.pow' не может не работать. Не могли бы вы напечатать 'input' и' input2'? –
Вы вычисляете 3^3 = 27, а не 2^3 = 8 - 2 не сохраняются, как вы думаете. Публикация окружающего кода поможет нам показать вам, почему – torquestomp
@ZouZou я не подставлю, что вы хотите, чтобы я сделал? – Mabulhuda