Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can we get one value back of two values in Android java?

How can we get one value back of two values? For example, if the user writes 100, how can we replace 100 with 50+50 in the text box? That is, suppose the user types 100 and on pressing the button, instead of 100, the text box should show 50+50 or 75+25 and so onŘŚ which is equal to 100 .A friend suggest me but I want to provide a low and a high value to the user. That is, if the user writes 100, it should be displayed as 75+25 or 80+20 etc. Thanks

    int customerInput = 100; //getvalue from user
        int splitValue = customerInput/2;
       saif.setText(splitValue+"+"+splitValue);

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What are the lows and highs that you need?

In your example it’s 1/4 and 3/4 so that would give you:

  int customerInput = 100; //getvalue from user
  int splitValue1 = customerInput/4;
  int splitValue2 = (customerInput/4)*3;
  saif.setText(splitValue+"+"+splitValue);

If you need it to be random you can use the Java function

int random = Random.nextInt(n)

This returns a random int in the range [0, n-1].
So in your case you would need a random number between 0 and 100

int customerInput = 100; //getvalue from user 
int random = new Random().nextInt(100); // [0, 100]
int random2 = 100 - random; // the other percent of your number
saif.setText(random+"+"+random2);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading