c转换成java代码 c语言转java转换器
如何将下面c语言代码转换成Java代码?
完整的直译为java方法是这样的,但是这样写dataLen的值必须小于等于数组长度,不然会出现下标越界的异常
创新互联建站专注于罗平企业网站建设,响应式网站建设,购物商城网站建设。罗平网站建设公司,为罗平等地区提供建站服务。全流程按需开发,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务
public int accumulativeVerification(int[] data, int dataLen) {
int sum = 0;
for (int i = 0; i dataLen; i++) {
sum += data[i];
}
return sum;
}
如果是意译(计算int数组的所有数之和),那么java可以这样写
public int accumulativeVerification(int[] data) {
int sum = 0;
for (int i = 0; i data.length; i++) {
sum += data[i];
}
return sum;
}
把C语言代码转成Java代码
package dis;
import java.io.*;
import java.math.*;
public class dis
{
public static void main(String [] s) throws Exception
{
Float a,b,c;
double x2;
double x1;
System.out.println("请输入a, b, c的值");
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
a=Float.parseFloat(bReader.readLine());
b=Float.parseFloat(bReader.readLine());
c=Float.parseFloat(bReader.readLine());
if (b*b - 4*a*c = 0)
System.out.println("输入的系数不对,b2-4ac不大于0!程序退出!");
else
{
x1 = (-b + Math.sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - Math.sqrt(b*b - 4*a*c))/2*a;
System.out.println("x1 = "+ x1);
System.out.println("x2 = "+x2);
}
return;
}
}
这段C代码如何转为java代码?
public class Test {
private int HASH_LOG = 14;
private int HASH_SIZE=(1 HASH_LOG);
private int HASH_MASK=(HASH_SIZE - 1);
public Long flz_hash(Long a){
Long l1 = 2654435769L;
Long index = (a * l1) 32-HASH_LOG;
return index HASH_MASK;
}
public static void main(String[] args) {
Test test = new Test();
long a = 2;
Long index = test.flz_hash(a);
System.out.println(index);
}
}
名称栏目:c转换成java代码 c语言转java转换器
网站网址:http://azwzsj.com/article/dogsdoi.html