题目一:八进制转换为十进制
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
int n = 0, i = 0;
System.out.print("请输入一个8进制数:");
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
char[] s = str.toCharArray();
while (s[i] != '\0') {
n = n * 8 + s[i] - '0';
i++;
if (i == s.length) {
break;
}
}
System.out.println("输入的8进制数转化为十进制为:" + n);
return;
}
}
题目二:809*??=800*??+9*?? 其中??代表的两位数, 809*??为四位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。
public class Test {
public static void main(String args[]) {
long a,b,i;
a = 809;
for(i = 10; i < 100; i++){
b = i * a;
if (b >= 1000 && b <= 10000 && 8 * i < 100 && 9 * i >= 100){
output(b, i);
}
}
return;
}
public static long output(long b, long i) {
System.out.println("809 * "+i+" = "+b+" = 800 * "+i+" + 9 * "+i);
return 0;
}
}