New Developer
- Forum posts: 2
Nov 20, 2012, 2:48:56 PM via Website
Nov 20, 2012 2:48:56 PM via Website
Hi all, fairly new to Android so I'll keep this as simple as possible. In my activity I have a set of strings (questions) stored in an array.
What I want to do is select a random string (ie question) and display it on the screen. I have tried the following code but nothing shows when I compile and run the app.
1String[] questions = { "question1", "question2", "question3", etc };
What I want to do is select a random string (ie question) and display it on the screen. I have tried the following code but nothing shows when I compile and run the app.
1int length = questions.length;
2for (int i = 0; i < length; i++)
3 {
4 int rand = (int) (Math.random() * length);
5 System.out.print(questions[rand]);
6 }
7 }
8}
2for (int i = 0; i < length; i++)
3 {
4 int rand = (int) (Math.random() * length);
5 System.out.print(questions[rand]);
6 }
7 }
8}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.