-4

I have a question and this one will be quick. I just need to convert this little snippet from C to Java.

Here is the C code

C code
(source: cip-labs.net)

Here is what I have done so far. I put $$$$ sings where I was super confused.

float benford10(int n, int d){
float j = $$$$$$(10, n-1), s=0, i;


for(i=$$$$($$$(10,(n-2))); i<=j-1; i++){
s+= $$$(1+(1/((i*10)+d)));
}
return s;
}

Can anyone help me translate the code from C to java? I would appreciate it so much. Thanks!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
ohGosh
  • 539
  • 1
  • 7
  • 10
  • 2
    you will find all function in Java Math class . http://download.oracle.com/javase/6/docs/api/java/lang/Math.html – harshit Oct 19 '11 at 17:29

2 Answers2

5

Most of the functions in C's math.h header have equivalents as static methods in Java's java.lang.Math class:

pow => Math.pow
floor => Math.floor
log10 => Math.log10
Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
2

import java.lang.math, the functions are rather similar.

AlwaysWrong
  • 526
  • 4
  • 9