Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with this code???

 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code below:-
class RandomArray{
public static void main (String args[] )
{
double[] samples = new double[50];
for (int i=0; i <50; i++)
samples[i] = 100.0*Math.randon();
double average = 0.0;
for (int i=0; i <50; i++)
average += samples[i];
average/= 50;
System.out.print(average);

}
}
gives me the following error when i try and compile it:
"RandomArray.java": Error #: 300 : method randon() not found in class java.lang.Math at line 10, column 25
I'm using JBuilder

Can anyone see what i'm doing wrong?
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You spelled the method name wrong. The Math class does not have a method named randon. It does, however, have a method named random. One letter makes a big difference in java.
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
100.0*Math.randon();
wowow~~
wrong spelling~~
you have to care about your code~
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tsk!
Silly me!!

Sorry.......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic