按照你的要求,C语言程序转换成的Java程序如下:
创新互联建站是网站建设技术企业,为成都企业提供专业的成都网站建设、网站设计,网站设计,网站制作,网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制适合企业的网站。十多年品质,值得信赖!
public class GGG {
public static String calculateBillMac(String input_str){
String str_buff_8 ="",str_buff_10 = "",str_return = "";
long sum8_1=0,sum8_2=0,sum10_1=0,sum10_2=0;//分别存储八进制和十进制不同算法取值的合计
for(int i=0 ;i input_str.length();i++){//对输入字符串的每一个字节进行循环
str_buff_8+=Integer.toOctalString(input_str.charAt(i));//将ASCII码值转换成八进制字符串
str_buff_10+=Integer.toString(input_str.charAt(i)); //将ASCII码值转换成十进制字符串
}
for(int i=1;i=str_buff_8.length();i++){
sum8_1 += (str_buff_8.charAt(i - 1) - '0')*i;
sum8_2 += (str_buff_8.charAt(str_buff_8.length()-i) - '0')*i;
}
for(int i=1;i=str_buff_10.length();i++){
sum10_1 += (str_buff_10.charAt(i - 1) - '0')*i;
sum10_2 += (str_buff_10.charAt(str_buff_10.length() - i) - '0')*i;
}
str_return=""+sum8_1%10+sum8_2%10+sum10_1%10+sum10_2%10;
return str_return;
}
public static void main(String[] args) {
System.out.println(calculateBillMac("abcdef"));
}
}
运行结果:
2739
这个数据和C语言用字符串"abcdef"测试的结果相同.
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;
}
}
用JBOSS好象可以编译(记不清了,公司现在不做这个了,呵呵),其实C和JAVA差不多的
import java.util.Scanner;
public class code{
public static void main(String args[]){
int zhu=0;
int ji=0;
int xing =0;
int da=0;
System.out.println("请输入星级:");
Scanner input = new Scanner(System.in);
xing = input.nextInt();
while(xing != 0){
System.out.println("请输入等级:");
ji = input.nextInt();
System.out.println("请输入主属性:");
zhu = input.nextInt();
switch(xing){
case 3:
da=149+zhu-(17+ji)/2;
break;
case 4:
da=149+zhu-(31+ji)/2;
break;
case 5:
da=149+zhu-(49+ji)/2;
break;
}
System.out.println("da="+da);
System.out.printn("请输入星级:");
xing = input.nextInt();
}
}
}
完整的直译为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;
}
方法1
PUBLIC short *make_pair_table(const char *structure)
{
/* returns array representation of structure.
table[i] is 0 if unpaired or j if (i.j) pair. */
short i,j,hx;
short length;
short *stack;
short *table;
length = (short) strlen(structure);//structure的长度
stack = (short *) space(sizeof(short)*(length+1));//stack是一个short型的指针数组,这里是分配空间
table = (short *) space(sizeof(short)*(length+2));//table和stack类似
table[0] = length;
for (hx=0, i=1; i=length; i++) {
switch (structure[i-1]) {//访问structure数组遍历,进行括号匹配
case '(':
stack[hx++]=i;//括号开始就+1
break;
case ')':
j = stack[--hx];
if (hx0) {
fprintf(stderr, "%s\n", structure);
nrerror("unbalanced brackets in make_pair_table");
}
table[i]=j;//存放左括号所在位置
table[j]=i;//存放右括号所在位置
break;
default: /* unpaired base, usually '.' */
table[i]= 0;
break;
}
}
if (hx!=0) {
fprintf(stderr, "%s\n", structure);
nrerror("unbalanced brackets in make_pair_table");
}
free(stack);//释放空间
return(table);//返回括号匹配结果
}
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款