Edit #1
Someone in comments suggested using Math.floor()
and intValue()
. How to implement it to my code? Is it still possible to run the program on Android?
What do I want to achieve?
I'm trying to create Android-compatible Java code (purpose is explained in comments in code). I'm new to Java, and still don't know about (probably basic) stuff like textboxes.
What do I have?
Right now I have code that:
- Generates
x
andy
based on array-defined integer range (needs rework; explained inWhat do I need?
below), andz
(answer-equal variable) that will be used to compare input with actual answer. - Code comparing input (variable
answer
) with actual answer (variablez
)
What do I need?
Every needed piece of code is explained in comments in code, but here's a list too:
- Textbox (integer input), in which user has to put answer to x*y (which is equal to z). Input should be a variable 'answer'
- Code randomizing
x
andy
, based on arrays
Code
public class numGen {
public static void main(String[] args) {
int[] firstNum = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int x = firstNum[/*Here program should put a random number out of firstNum array*/];
int[] secondNum = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int y = secondNum[/*Here program should put a random number out of secondNum array*/];
int z = x*y;
/*
Here I'm looking to insert textbox (integer input), in which user has to put answer to x*y (which is equal to z). Input should be a variable 'answer'
*/
/*
And that's the code comparing textbox input with z variable:
*/
if (answer == z);{
System.out.println("Correct."); // and after good answer program should repeat with new x and y values...
} else {
System.out.println("Incorrect. Try again."); // ...and here not.
}
System.out.println(x + " * " + y);
}
}