Creating multiple nextInts based on args.

Discussion in 'Plugin Development' started by TopGear93, Apr 20, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    What id like to do is create multiple nextInts based on what args[1].equals. So if i type /random num 10
    id like it to create 10 nextInts and convert those nextInts into Strings.

    Full Example:

    /random num 10
  2. Offline


    Okay, I think I understand what you're getting at.

    Try using a for loop, have the for loop add numbers onto a string. Here's to save you some time.

                if (
    args.length 0){
    Player p = (Player)sender;
    String args0 args[0];
    String toPlayer "Random Numbers:";
    int NumRan Integer.valueOf(args0);
                    for (
    int i 0<= NumRani++){
    //add a random number to the string here

    Random ran = new Random();
    toPlayer += " ";
    toPlayer += ran.nextInt(9999);

    Of course, style the code accordingly. I hope this was helpful in some way!
    TopGear93 likes this.
  3. Offline


    BTW, there might be a few typos in here, but it shud work :D.
    2. String s = args[0]
    3. int r = 0;
    4. try {
    5. int r = Integer.parseInt(s);
    6. }
    7. catch(NuberFormatException e) {
    8. sender.sendMessage(ChatColor.RED+"This must be a nuber!")
    9. return true;
    10. }
    11. String fmsg = "";
    12. for (int i = 0; i <= r; i++) {
    13. //why not, 0 thru 100!
    14. Random rand = new Random();
    15. int rr = rand.nextInt(100);
    16. fmsg += (i = r ? rr : r +",");
    17. }
    TopGear93 likes this.
  4. Offline


    @Alectriciti & dillyg10

    Thanks for the help. Sorry i didnt clearly explain what i was looking to do. From looking at the code above, i believe this will work.
  5. Offline


    Why create a new Random object each iteration? That can eat up memory possibly. Also it's slower. Create it outside of the loop and then just call nextInt on it :p
Thread Status:
Not open for further replies.

Share This Page