Android Build a Simple Android App Basic Android Programming Using the Random Class

bahati kayombo
PRO
bahati kayombo
Pro Student 177 Points

need some help with creating a string variable etc

getting an error when running the string

RandomTest.java
Random randomGenerator = new Random();

int randomNumber = randomGenerator.nextInt(10);

intAsString [] facts = {"my name is B"};

intAsString fact = "";

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

There are a few syntax errors in the lines you've added. Let's start over with these two lines:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);

Next, you want to declare a variable and then make it a String type. For a new variable, we always start with the data type first, so your next line would start with:

String

With that, we need to give the new variable a name, so we'd have:

String intAsString

We could stop right here and have an empty, or uninitialized variable, if we add a semicolon like this:

String intAsString;

(Remember that all statements in Java like this need to end in a semicolon.)

But wait, there's more! We want to store a text value in this variable! What operator do we use to put a value in a variable? Here's a hint: look at the provided line that declares the randomNumber variable.

That should get you started, but I don't want to give away the whole answer. Hopefully that's enough, but let us know if you need more help after trying it again.