...

Java Programming

zahzuf
10-05-2004, 03:17 PM
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);

}
}

sad69
10-05-2004, 10:55 PM
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.

Jason
10-05-2004, 11:13 PM
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

Brandoe85
10-06-2004, 01:06 AM
I can see a couple errors just glancing at it. For one, this is an error:

System.out.println(Player "+(i+1)+": "+results[i]);


Secondly this is another error:

System.out.println(Player "+player+" wins with "+maxN);


Them are the most obvious to me just by glancing at it.

JPM
10-07-2004, 12:04 AM
Seems like your using Java some places and then some javascript.
Look

here (http://java.sun.com/j2se/1.4.2/docs/api/index.html) for java random numbers.

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

i<nr.... you haven't defined nr



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum