本文目录一览:
c语言如何转化为java 语言
public class Test{
public staitc void main(String args){
int i,j,k=3;
for(i=0;i4;k=k-1-i,i++)
{
for(j=0;j4+i;j++)
{
if(jk)
System.out.print(" ");
else
{
System.out.print("*");
j++;
}
}
}
k=3;
}
}
保存为Test.java,然后运行javac Test.java和java Test就可以运行了。。
c语言转java,拜托各位
你要把这个转为java程序么?
package org.crazyit.app.ServletAPI;
import java.util.Arrays;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
char [] ax={'1','2'};
char[] ac = reverse(ax);
System.out.println(Arrays.toString(ac));
char sz[] = new char[128];
System.out.println("请输入你要转换的数 : ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println("请输入进制 : ");
int c = scanner.nextInt();
cover_to(n, c, sz);
System.out.println("转换成 " + c + "进制是 :" + Arrays.toString(sz));
}
public static void cover_to(int num, int base, char sz[]) {
int t = num;
int r = 0;
int n = 0;
int i = 0;
if (base 2 || base 32) {
return;
}
while ((n = t / base) != t) {
r = t % base;
t = n;
if (r 9)
sz[i++] = (char) ('A' + (r - 10));
else
sz[i++] = (char) ('0' + r);
}
sz[i] = 0;
reverse(sz);
}
public static char [] reverse(char [] arr) {
int end= arr.length-1;
int begin =0;
while(begin end){
char temp = arr[begin];
arr[begin] = arr;
arr = temp;
begin++;
end--;
}
return arr;
}
}
怎样把一下的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);
}
}