Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.uorjaipur.higherorlower;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- import java.util.Random;
- public class MainActivity extends AppCompatActivity {
- Random random = new Random();
- int randNum = random.nextInt(19) + 1;
- public void guess(View view){
- EditText editText = (EditText) findViewById(R.id.editText);
- int numInput = Integer.parseInt(editText.getText().toString());
- //Log.i("Variable type",editText.getText().getClass().toString());
- //Log.i("EditText",editText.getText().toString())
- //Log.i("int value",Integer.toString(randNum));
- Log.i("Random number",Integer.toString(randNum));
- if (numInput==randNum){
- Toast.makeText(this, "You've got the right number : "+randNum, Toast.LENGTH_LONG).show();
- } else if (numInput>randNum){
- Toast.makeText(this, "Lower", Toast.LENGTH_SHORT).show();
- } else{
- Toast.makeText(this, "Higher", Toast.LENGTH_SHORT).show();
- }
- }
Add Comment
Please, Sign In to add comment