Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java Programming

    Is there anybody can fix my programming.

    class NilaiTinggi{
    public static void main (String[ ] args){

    int [] maxN;
    int [] player;
    maxN=new int [0];
    player=new int[1];

    for(i=0;i<nr;i++) // Generating the random numbers ( 1 - 6)
    {
    results[i] = Math.floor(Math.random() * 6) +1;
    System.out.println(Player "+(i+1)+": "+results[i]);

    }

    // Finding the highest nr

    for(i=0;i<results.length;i++)
    {
    if(results[i] > maxN)
    {
    maxN = results[i];
    player = i + 1;
    }
    }
    System.out.println(Player "+player+" wins with "+maxN);

    }
    }

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I haven't compiled it, but then again I shouldn't have to.

    Why do you think it needs to be fixed? What problem(s) do you see that you can't seem to find a solution for?

    Is this a homework problem?

    Sadiq.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what is the type of error your getting and where/what are all these other variables defined?

    next time put your code in the appropriate brackets...


    Jason

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I can see a couple errors just glancing at it. For one, this is an error:
    Code:
    System.out.println(Player "+(i+1)+": "+results[i]);
    Secondly this is another error:
    Code:
    System.out.println(Player "+player+" wins with "+maxN);
    Them are the most obvious to me just by glancing at it.
    Last edited by Brandoe85; 10-06-2004 at 07:02 AM.

  • #5
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seems like your using Java some places and then some javascript.
    Look

    here for java random numbers.

    for(i=0....
    should be for(int i=0....

    i<nr.... you haven't defined nr
    <JPM />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •