java 面试编程题,如下,求解,第2题
2个回答
展开全部
这是我的代码,经测试没问题请采纳
public class TestString {
public long change_to_10 (String str) {
int i = str.length();
long l = 0;
for(int p = 0;p < i-1; p++ ){
long f = (long) ((Integer.parseInt(str))/Math.pow(10,i-1));
l = l + f*7;
}
l = (long) (l + (Integer.parseInt(str))%10);
return l;
}
public static void main(String args[]){
String string = "12";
TestString testString = new TestString();
long l = testString.change_to_10(string);
System.out.println(l);
}
}
结果:
public class TestString {
public long change_to_10 (String str) {
int i = str.length();
long l = 0;
for(int p = 0;p < i-1; p++ ){
long f = (long) ((Integer.parseInt(str))/Math.pow(10,i-1));
l = l + f*7;
}
l = (long) (l + (Integer.parseInt(str))%10);
return l;
}
public static void main(String args[]){
String string = "12";
TestString testString = new TestString();
long l = testString.change_to_10(string);
System.out.println(l);
}
}
结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询