我是创造减法,乘法,除法和加法的Android应用程序与循环语句如何减法,乘法和除法与循环语句
case 1: if user insert= 3 then looping = 3x
case 2: user input 1st looping = 5 then dialog show = 5
case 3: user input 2nd = 10 then dialog show 5+10
case 4: user input 3rd = 90 then dialog show 5+10+90
这是我附加码
package com.test.testing;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
public class arithmatic extends Activity {
int y = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
final LayoutInflater inflater = this.getLayoutInflater();
final View v=inflater.inflate(R.layout.dialoginputloop, null);
new AlertDialog.Builder(arithmatic.this)
// .setIcon(R.drawable.ic_launcher)
.setTitle("Operator")
.setView(v)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
EditText op = (EditText)v.findViewById(R.id.operator);
int n = Integer.valueOf(op.getText().toString());
for (int i = 0;i<n;i++){
LayoutInflater inflater = arithmatic.this.getLayoutInflater();
final View v2=inflater.inflate(R.layout.dialoginputnumber, null) ;
new AlertDialog.Builder(arithmatic.this)
//.setIcon(R.drawable.ic_launcher)
.setTitle("input number")
.setView(v2)
.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
EditText number = (EditText)v2.findViewById(R.id.number);
String a = number.getText().toString();
int x = Integer.valueOf(a);
y = y + x; //my formula to addition looping
new AlertDialog.Builder(arithmatic.this)
.setTitle("result")
.setMessage(Integer.toString(y))
.setNeutralButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
})
.show();
}
})
.show();
}
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
})
.show();
}
}
如何创造减法,乘法和除法的公式?
这些案件或数字步骤? – thegrinner
这可能是有史以来最明目张胆的作业。 –
看看这一行。我不认为它会做你认为它的做法:“int y = y + x;” –