本文目录一览:
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 语言
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代码
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;
}
}