java - 我需要一些帮助将一些代码从 C 转换为 Java

标签 java c code-translation

我有一个问题,这个问题会很快解决。我只需要将这个小片段从 C 转换为 Java。

这是C代码

C code
(来源:cip-labs.net)

这是我到目前为止所做的事情。我把 $$$$ 放在我 super 困惑的地方。

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;
}

谁能帮我把C代码翻译成java代码吗?我将非常感激。谢谢!

最佳答案

C 的 math.h header 中的大多数函数都与 Java 的 java.lang.Math 中的静态方法等效。类:

pow => Math.pow
floor => Math.floor
log10 => Math.log10

关于java - 我需要一些帮助将一些代码从 C 转换为 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7825402/

相关文章:

java - eclipse JDT插件使用方法

c - 解释一下这个程序中的esp-ebp

c# - 自动将简单的 C++ 代码转换为 C#

c - Switch 语句用法 - C

php - 我想将 "Read directory"代码从 php 翻译为 python

c++ - C99 printf 格式化程序与 C++11 用户定义文字

java - 在 Google App Engine Java 上存储小型且简单的持久数据?

java - 如何在框架内调整大小和绘制组件

java - 如何验证复制构造函数的参数?

c - 将int32存储在int8指针中