(Android Studio) Even or odd

0

I'm a beginner in Android Studio and need to make an app that gets a number in EditText and then tell me if it's even or odd, it follows my current code: I do not know what and where to put it to when I hit the button (I already did) have this result ... Help

public class exercicio1 extends AppCompatActivity {

TextView tInforme;
EditText tValor;
Button btDescobrir;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exercicio1);

    tInforme = (TextView) findViewById(R.id.tInforme);
    tValor = (EditText) findViewById(R.id.tValor);
    btDescobrir = (Button) findViewById(R.id.btDescobrir);}


        public void setbtDescobrir(View v) {
            String guessStr = tValor.getText().toString();
            int theGuess = Integer.parseInt(guessStr);

        }}
    
asked by anonymous 14.06.2017 / 16:07

1 answer

0

Use the % operation to get you the rest of a split. In case it divides by 2% with% and if the result is 0, it means that it is even if it is not even

edited:

String guessStr = tValor.getText().toString();
   int theGuess = Integer.parseInt(guessStr);
   int valor = theGuess%2;
   if(valor == 0){
      //imprima é par
   }
   else if(valor == 1){
    // imprima é impar
   }
    
14.06.2017 / 16:10