JavaME - how do i use this Random Method

Hi , I read through the api of javame.
I wanted to create a number ranging from 0 to 9 at random .
How do i do it with this Random method . can anyone show me a example of generate random 0 to 9 and set this generated number as a string cause i will need compare it later to do some other stuffs.
thanks , dukestars will be the best i could return the favors..

I wanted to create a number ranging from 0 to 9 at randomjava.util.Random has a method nextInt() which "Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence."
http://java.sun.com/javame/reference/apis/jsr139/java/util/Random.html#nextInt(int)
So you could obtain your int with
import java.util.Random;
// ... later
Random random = new Random();
int myInt = random.nextInt(10);If you wanted a random number at various places in a class then that class might make random an instance variable so that it can be reused. Each call to nextInt() produces an int at random.
and set this generated number as a string
String myString = "" + myInt;
// or
myString = String.valueOf(myInt);http://java.sun.com/javame/reference/apis/jsr139/java/lang/String.html#valueOf(int)
You would do well to also have a read of the opening part of Sun's Tutorial if you're unfamiliar with the language.

Similar Messages

  • How do I use this StringManip method?

    I want to be able to use the following method:
    java.lang.Object
    |
    --SSF.OS.BGP4.Util.StringManip
    public class StringManip
    extends java.lang.Object
    This class contains public utility methods useful for manipulating character strings.
    static java.lang.String ws(int len)
    Creates a string of whitespace composed of space characters only.
    ws
    public static final java.lang.String ws(int len,
    int min)Creates a string of whitespace composed of space characters only.
    Parameters:
    len - The length (in characters) of the whitespace to be created. A negative value will be treated as a 0.
    min - The minimum length (in characters) of the whitespace to be created.
    Returns:
    a string composed only of spaces
    but everytime i try to use this in my code, it gives me an error.
    can someone tell me what i need to import, extend, or implement in order to use the ws method?
    Thanks.

    but everytime i try to use this in my code, it gives me an error.Do you seriously expect anyone to be able to tell what the problem is from this description? How about some details?

  • How do i get a list of all Roles defubed under a particular OrganizationalUnit? How can i use LDAPConnection.search method for this?

     

    Sorry for the typographical mistake.
    Please read the question as:"How do i get a list of all Roles defined under a particular OrganizationalUnit? How can i use LDAPConnection.search method for this?"

  • HT1222 I bought used iPhone and on this iPhone I'm not able to make new account  on i Cloud'.  How can I use this iCloud's on used iPhone   Please help me

    I bought used iPhone and on this iPhone I'm not able to make new account  on i Cloud'.  How can I use this iCloud's on used iPhone   Please help me
    When I logging there it told me that maximum no of iCloud's Account already activated on this iPhone.
    Please help me how can I open new iCloud's account on this iPhone
    Regard
    Faiz khan

    Set up the account using a desktop or laptop, then sign
    into that account on your iPhone.
    I am not aware of any method around the restriction once
    the maximum has been created on any individual iPhne.

  • I have Iphone 4G. I bought when I studied in Usa. Then I returned to  Uzbekistan this Iphone doesn't work. How I can use this phone? Can you help me?

    I have Iphone 4G. I bought when I studied in Usa. Then I returned to  Uzbekistan this Iphone doesn't work. How I can use this phone? Can you help me?

    shohjahon wrote:
    I have Iphone 4G.
    No, you do not.  It simply is not possible to have a device that does not exist.
    Most likely, you have an iPhone 4.  There is no 4G iPhone.
    shohjahon wrote:
    I bought when I studied in Usa. Then I returned to  Uzbekistan this Iphone doesn't work.
    Yes, it does work.  It is carrier locked to AT&T, just like all GSM iPhones sold in the US since their introduction.
    shohjahon wrote:
    How I can use this phone?
    You can use the phone as it is, but it will be very expensive with AT&T international roaming plans.
    There is no official way to unlock the phone for use with another carrier.
    Your options:
    Sell the device and purchase one intended for use in your country.
    Find unofficial method to unlock
    Use as an iPod Touch.
    No one here can provide you with assistance on getting you AT&T locked iPhone to work on another carrier.

  • How can i use Catalog in Method Type?

    Dear Experts,
    How can i use Catalog in Method Type?
    I want to use Multiple method type mean require selection option(help from catalog)and also need to entere the result against certain parameters. So how can i do this possible ?
    Except use of additional infrmation field
    Regards,
    Abhishek

    Hi,
    Can i provide selection option F4 help at Method while enteing the result?
    Because for 1 MIC as per buyer method testing different so it will come alternately.
    i.e i have 3 methods which comes altarnative for one MIC
    TST_ISO
    TST_AATC
    TST_ASTM
    So how it is possible???

  • How can I use a COM Method?

    There are a method in a dll.
    And method is a COM Method. I use DLL Export Viewer to look properties.
    I use Form Developer 6.0.

    I dont how a com method is invoked. I assume u r using 6i client server.
    You can use host method to invoke any executable or you might need to try ORA_FFI
    Is this COM method can be converted to an executable?
    How do you call this com method other than forms?
    Rajesh

  • I have an old external drive with a firewall connection-How do I use this on my Mac with it's USB3 ports?

    I have an old external drive with a firewall connection-How do I use this on my Mac with it's USB3 ports?

    Does your Mac have ThunderBolt ports?
    There are ThunderBolt to FireWire adapters.
    As far as I know there are no FireWire to USB 3 adapters.
    Allan

  • HT201209 I redeemed a gift card of $15 in mu Itunes Store.  I purchased one book in IBooks of $6.99 now the balance in my iTunes store is $ 7.10.  How Do I use this balance to buy another book or music from my Itunes Store It is not using my balance?

    I redeemed a gift card of $15 in my Itunes Store.  I purchased one book in IBooks of $6.99 now the balance in my iTunes store is $ 7.10.  How Do I use this balance to buy another book or music from my Itunes Store It is not using my balance?  Whenver I try to make a purchase it is trying to charge my Visa Credit card.  My Credit card is no more active. I want to remove my Visa credit card and use Itines gift card fro purchase in Itunes store.
    TIA
    Bikram Suri
    <Email Edited by Host>

    Sir,
    I thought So too but then I went to Itunes Library and try and buy a single song from an album for $1.29.  Now my Itunes Gift card balance is $ 7.10 as I mentioned earlier. it still did not let me buy and kept trying billing my Visa card.
    Should I restart my PC and Itunes and retry. What do you suggest?
    regards
    Bikram Suri
    [email protected]

  • Limited storage in iPhone so i bought 20g iCloud. how can i use this iCloud storage in my device to store music and photos?

    I have a limited storage in iPhone so i bought 20g iCloud. how can i use this iCloud storage in my device to store music and photos?

    Welcome to the Apple Community.
    You could sign up for iTunes match and use iCloud photo library with optimisation enabled. The later will keep optimised photos on your device and iTunes match will let you access your whole collection and make room for newer content by removing older unplayed items.

  • How can i use this  function module

    Hai
    How can i use this function module /SAPHT/SALES_ORDER_READ, already apply the some parameters in this function module, but it shows the error , please tell me, how to declare the parameters in this function module ,
    thanks
    neelima

    Hi
    For a particular sales order,you have to pass the order number and the item number in the sales order.
    It will display the rest of the values which u can capture them using internal tables.
    Regards,
    Vishwa.

  • I have a i phone 4,4.3.5 bought from uk i used this in uk but now i am in india how can i use this phone in other networka with out jailbreak such ntype of softwares

    i have a iphone 4,4.3.5 bought from uk i used this phone in uk,now i am in india how can i use this in another networks without jailbreak such type of softwares

    Where did the phone come from as most of the UK carriers unlock phones, but the fact that you are now abroad may be a problem.

  • I purchased a iphone i USA. How can i use this iphone in india with vodafone.

    I Purchased a iPhone 5s in USA. How can I use this phone in India with Vodafone.
    <Edited By Host>

    First, the iPhone would need to be unlocked. That would depend on where you bought it. Next, the North American phone would not work with all of the networks outside of the US. Also, the warranty for the device is only good in the US, so if you have a problem with the phone, you would need to bring it back to the US to an Apple Store. Where did you purchase the phone?

  • I purchased Adobe Illustrator CS2 on CD many years ago and now i have bought a new iMac computer it won't let me install from the CD's. How can i use this product on iMac ?

    I purchased Adobe Illustrator CS2 on CD many years ago and now i have bought a new iMac computer it won't let me install from the CD's. How can i use this product on iMac ?

    Because the Nano was previous synced to another comuter/iTunes library.
    See the following:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • I do not have a credit card to purchase in the itunes store.  I do have an itunes gift certificate.  How can I use this card when I do not have a credit card?

    I do not have a credit card to get through to the itunes store.  I do have an itunes gift certificate.  How do I use this if I cannot get through the ID part to redeem my gift card? Thanks

    Hi cstafford84,
    Thanks for visiting Apple Support Communities.
    If you have not logged in to the iTunes Store before, first follow the steps in this article to create your account without providing a credit card:
    Creating an iTunes Store, App Store, iBooks Store, and Mac App Store account without a credit card
    http://support.apple.com/kb/HT2534
    Next, use the steps in this article to redeem your gift card:
    Redeeming iTunes Gift Cards and download codes
    http://support.apple.com/kb/ht1574
    All the best,
    Jeremy

Maybe you are looking for