1、编写程序
我新建了一个项目TestApp,参数为:
Package Name: com.android.testapp
Activity Name: MainActivity
Application Name: TestApp
以下是MainActivity的源代码:
packagecom.android.testapp;
importandroid.app.Activity;
importandroid.os.Bundle;
publicclassMainActivityextendsActivity {
/** Called when the activity is first created. */
@Override
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
publicintsum(inta,intb) {
returna + b;
}
publicintsubstract(inta,intb) {
returnb - a;
}
}
其中,我故意将减法的a – b写成了b – a。