Attempted GCF app for Android

Posted by Aaron on Stack Overflow See other posts from Stack Overflow or by Aaron
Published on 2010-06-15T00:10:12Z Indexed on 2010/06/15 0:12 UTC
Read the original article Hit count: 202

Filed under:
|

I am new to Android and am trying to create a very basic app that calculates and displays the GCF of two numbers entered by the user. Here is a copy of my GCF.java:

package com.example.GCF;

import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class GCF extends Activity {
private TextView mAnswer;
    private EditText mA, mB;
    private Button ok;
    private String A, B;
    private int iA, iB;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mA = (EditText) findViewById(R.id.entry);
        mB = (EditText) findViewById(R.id.entry1);
        ok = (Button) findViewById(R.id.ok);
        mAnswer = (TextView) findViewById(R.id.answer1);

        ok.setOnClickListener(new OnClickListener() { 
        public void onClick(View v)  
        {               
            A = mA.getText().toString();  
            B = mB.getText().toString();   
        } 
        });

        // the String to int conversion happens here
        iA = Integer.parseInt(A.trim());
        iB = Integer.parseInt(B.trim());

        while (iA != iB) {
        int[] nums={ iA, iB, Math.abs(iA-iB) };
        Arrays.sort(nums);
            iA=nums[0];
        iB=nums[1]; 
        } 
        updateDisplay();
    }
        private void updateDisplay() {
          mAnswer.setText(
            new StringBuilder().append(iA));

        }

}

Any Suggestions? Thank you!

© Stack Overflow or respective owner

Related posts about java

Related posts about android