gpt4 book ai didi

java - 如何计算具体值 - Eclipse

转载 作者:太空宇宙 更新时间:2023-11-04 15:22:10 26 4
gpt4 key购买 nike

我有 5 个 XML 纯文本,我想要执行以下操作:

8 000 000 000/文本1 * 文本2/文本3 * 文本4 - 文本5

这是我所拥有的:

    btn = (Button)this.findViewById(R.id.button1);
text1 = (EditText)this.findViewById(R.id.editText1);
text2 = (EditText)this.findViewById(R.id.editText2);
text3 = (EditText)this.findViewById(R.id.editText3);
text4 = (EditText)this.findViewById(R.id.editText4);
text5 = (EditText)this.findViewById(R.id.editText5);
text = (TextView)this.findViewById(R.id.textView1);
textB = (EditText)this.findViewById(R.id.editText);

btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String a,b,c,d,e,f;
Integer vis;
a = text1.getText().toString();
b = text2.getText().toString();
c = text3.getText().toString();
d = text4.getText().toString();
e = text5.getText().toString();
f = textB.getText().toString();
vis = Integer.parseInt(a)+Integer.parseInt(b)+Integer.parseInt(f); //And so on..
text.setText(vis.toString());

}});
}

我的问题:如何计算这些值?我尝试对此进行测试,但该应用程序自行关闭了。有什么帮助吗?

最佳答案

String.valueOf() 返回一个字符串。您不能对字符串进行除法或执行任何非加法数学运算符,这解释了您的错误。

The operator / is undefined for the argument type.

换句话说,您正在尝试执行类似于 "3"* "3" 的操作,而您实际上想要 3 * 3

您可能正在寻找Integer.parseInt()它接受一个字符串并输出一个整数值。例如:

String s = "1234";
int i = Integer.ParseInt(s);
System.out.println(i * 3);

关于java - 如何计算具体值 - Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20306491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com