Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:18:29+00:00 2026-05-30T21:18:29+00:00

In short i have a method which selects a random operation and generates two

  • 0

In short i have a method which selects a random operation and generates two random numbers, it then creates an expression out of them as a string and changes a textview to show that expression as show here:

public String Nov2()
{
    String[] ops = new String[] {" + ", " - ", " * ", " / "};
    int i = rand.nextInt(4-0) + 0;
    String op1 = ops[i];

    int novnum1 = rand.nextInt(101-1) + 1;

    int novnum2 = rand.nextInt(101-1) + 1;

    String nov2Exp = novnum1 + op1 + novnum2 + " = ";

    setContentView(R.layout.gameview);

    TextView display = (TextView) findViewById(R.id.exp);

    display.setText(nov2Exp);

    return nov2Exp;
}

I have a second method which will put a number as a string into a second textview depending on which button is pressed:

@Override
public void onClick(View c) {

    switch (c.getId()) 
    {
        case R.id.keypad_1:
            TextView prs1 = (TextView) findViewById(R.id.ans);
            if (prs1.getText().equals("?"))
            {
                prs1.setText("1");
            }
            else
            {
            prs1.append("1");
            }

            break;

What i need is that when the user pushes another button the answer to expression will be calculated and compared with the contents of the answer textview, i’ve done some research on maths expression parsing and its proving far too complex for me to implement. Would i need to somehow return mutliple variables of different types from my method or am completely wrong? Can anyone help me?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:18:30+00:00Added an answer on May 30, 2026 at 9:18 pm

    You can define a custom data type:

    public class Result {
        private String result1;
        private int result2;
        // etc.
    }
    

    and have your method return an object of this type.

    Edit:

    Well you can do something like:

    public int Nov2()
    {
        char[] ops = new char[] {'+', '-', '*', '/'};
        int i = rand.nextInt(4-0) + 0;
        char op1 = ops[i];
    
        int novnum1 = rand.nextInt(101-1) + 1;
    
        int novnum2 = rand.nextInt(101-1) + 1;
    
        int result = 0;
    
        switch(op1) {
            case '+': result = novnum1 + novnum2; break;
            case '-': result = novnum1 - novnum2; break;
            case '*': result = novnum1 * novnum2; break;
            case '/': result = novnum1 / novnum2; break;
        }
    
        String nov2Exp = novnum1 + " " + op1 + " " + novnum2 + " = ";
    
        setContentView(R.layout.gameview);
    
        TextView display = (TextView) findViewById(R.id.exp);
    
        display.setText(nov2Exp);
    
        return result;
    }
    

    This method will generate you a new expression, put it on the screen and then return the result. You can store it somewhere and when the user clicks the button compare it with his input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method invoking bean which calls a method to perform some sort
I have a UIActionSheet (sheet A for short) with a switch statement of which
I have 14 LINQ queries to resolve in one method. None of them have
I have the web service, which has method State() that returning the List. where
I have a a form in Django with two inline forms. One of them
I have the following code which calculates the median of a group of numbers
Hi I have a datagridview which binds XML manually. I wish to sort out
I have a problem with how the List Sort method deals with sorting. Given
I'd like to use the somelist.sort() method to do this if possible. I have
To make a long story short I have to use processing in a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.