1x1=1
1x2=2
1x3=3
.
1xj=j
2x1=2
.
.
ixj=(i*j值)
----------------------------------------以上為題目------------------------------------------------------
HelloAndroid.java
package can.taiwan.hello;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int i,j;
for(i=1;i<10;i++)
{
for(j=1;j<5;j++)
{
TextView textView = (TextView)findViewById(R.id.view);
if(j*i<10)
{
textView.append("\t"+j+" x"+i+"="+" \t"+(j*i)+"\t");
}
else
{
textView.append("\t"+j+" x"+i+"="+(j*i)+"\t");
}
}
TextView textView = (TextView)findViewById(R.id.view);
textView.append("\n");
}
}
}
main.xml
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout android:orientation="vertical" android:gravity="center|center_vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#B03060" android:text="學號:49725116" android:id="@+id/view2"/> <TextView android:layout_height="113dp" android:layout_width="match_parent" android:id="@+id/view"/> </LinearLayout>
結果 :
第一次分享自己的程式,請各位多多指教 :D

沒有留言:
張貼留言