Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » HELP ME PLEASE (Some basic java)(Help)
icon4.gif  HELP ME PLEASE (Some basic java) [message #1492355] Sat, 29 November 2014 19:54 Go to next message
Bostjan Mesnjak is currently offline Bostjan MesnjakFriend
Messages: 1
Registered: November 2014
Junior Member
Hey i need some help, this is the code i wrote, and i want now to pop out the rendum string (myNames) i know only how to pop out the string 1, 2 or 3 but can you help me that it pop out randum from 1 to 3! Sorry for my very bad eng! And thanx for help!


final String[] myNames = new String[3];
myNames[0] = " JOKE 1 ";
myNames[1] = "JOKE 2";
myNames[2] = "JOKE 3";

pushMe.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textOne.setText(myNames[RANDOM]);
Re: HELP ME PLEASE (Some basic java) [message #1497090 is a reply to message #1492355] Wed, 03 December 2014 14:36 Go to previous message
Javin Paul is currently offline Javin PaulFriend
Messages: 48
Registered: July 2011
Location: mumbai
Member

You can use Math.random() to generate random number between 0.0 to 1.0, later you can multiply it to 10 or 100 depending upon how many random number you will need, mostly depends upon how many elements you have in your array. Since here you three elements, you just multiply with 3 and cast it to int. For code example, you can take a look here
Previous Topic:Hi guys need help with Trapezoidal Rule Java code
Next Topic:Java Error.
Goto Forum:
  


Current Time: Tue Apr 23 07:33:14 GMT 2024

Powered by FUDForum. Page generated in 0.02924 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top