怎么把c代码改成java 怎么把c代码变成软件
怎样把一下的C语言程序改成java程序?
修改成Java后的代码:
龙华网站建设公司创新互联,龙华网站设计制作,有大型网站制作公司丰富经验。已为龙华上千家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的龙华做网站的公司定做!
public class Demo {
public static int gcd(int a, int b, int c) {
int min, i;
if(a b) {
if(b c) {
min = c;
} else {
min = b;
}
} else {
if(a c) {
min = c;
} else {
min = a;
}
}
if(b c) {
if(c a) {
min = a;
} else {
min = c;
}
} else {
if(b a) {
min = a;
} else {
min = b;
}
}
if(a c) {
if(c b) {
min = b;
} else {
min = c;
}
} else {
if(a b) {
min = b;
} else {
min = a;
}
}
for(i=min; i=1; i--) {
if(a%i==0 b%i==0 c%i==0) {
break;
}
}
return i;
}
public static void main(String[] args) {
int a = 1, b = 0, c = 0, i, k = 0, j = 0, m = 0, n = 0, z, y;
while(a 9) {
b = 1;
while(b 9) {
c = 1;
while(c 9) {
if(gcd(a,b,c) == 1) {
System.out.println(a + ";" + b + ";" + c);
k++;
z = b*b - 4*a*c;
if(z == 0) {
j++;
} else if(z 0) {
m++;
for (y=1; yz/2; y++) {
if (y*y==z) {
System.out.println("解答是有理数。");
}
}
} else {
n++;
}
}
c++;
}
b++;
}
a++;
}
System.out.println("N = " + k);
System.out.println("N2 = " + j);
System.out.println("N3 = " + m);
System.out.println("N4 = " + n);
i = gcd(a, b, c);
}
}
这段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代码
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 static void main(String[] args) {
String pass = "123456";
byte[] data;
byte[] salt = new byte[4];
byte[] digest1 = new byte[20];
byte[] tmpptr;
int i, j;
int len = 4 + pass.length();
// c语言中打开linux文件中的/dev/urandom产生随机数
// java这里模拟了
Random random = new Random();
salt[0] = (byte) random.nextInt(128);
salt[1] = (byte) random.nextInt(128);
salt[2] = (byte) random.nextInt(128);
salt[3] = (byte) random.nextInt(128);
System.out.print("Salt:");
for (i = 0; i 4; i++) {
System.out.print(Integer.toHexString(salt[i]) + " ");
}
System.out.println();
data = new byte[len];
for (i = 0; i 4; i++) {
data[i] = salt[i];
}
char[] passArr = pass.toCharArray();
for (i = 4; i len; i++) {
data[i] = (byte) passArr[i - 4];
}
System.out.print("\nData:");
for (i = 0; i len; i++) {
System.out.print(Integer.toHexString(data[i]) + " ");
}
System.out.println();
digest1 = sha1(data);
for (i = 0; i 20; i++) {
System.out.print(Integer.toHexString(digest1[i]) + " ");
}
System.out.println();
data = digest1;
for (j = 0; j 10000; j++) {
tmpptr = sha1(data);
data = tmpptr;
}
for (i = 0; i 20; i++) {
System.out.print(Integer.toHexString(data[i]) + " ");
}
System.out.println();
}
public static byte[] sha1(byte[] origin) {
try {
MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
return mdTemp.digest(origin);
} catch (Exception e) {
return null;
}
}
大体上是这样
当前题目:怎么把c代码改成java 怎么把c代码变成软件
当前链接:http://myzitong.com/article/docpopg.html