问题描述
答案提交
解题思路
主要考察进制间的转换和获取String变量单个字符并转化为整数
AC代码
public class Main {
public static void main(String[] args) {
//直接输出结果,避免运算超时
System.out.println(215040);
/*
int i = 0, num = 0;
while (i++ >= 0) {
String binary = Integer.toBinaryString(i);
String octal = Integer.toOctalString(i);
String decimal = Integer.toString(i);
String hex = Integer.toHexString(i);
int bAll = 0, oAll = 0, dAll = 0, hAll = 0;
for (int j = 0; j < binary.length(); j++) {
// 不能用减去字符0的方法,因为十六进制会有字符a~f,当然也可以分类讨论。
// bAll += binary.charAt(j) - '0';
bAll+=Character.getNumericValue(binary.charAt(j));
}
for (int j = 0; j < octal.length(); j++) {
// oAll += octal.charAt(j) - '0';
oAll+=Character.getNumericValue(octal.charAt(j));
}
for (int j = 0; j < decimal.length(); j++) {
// dAll += decimal.charAt(j) - '0';
dAll+=Character.getNumericValue(decimal.charAt(j));
}
for (int j = 0; j < hex.length(); j++) {
// hAll += hex.charAt(j) - '0';
hAll+=Character.getNumericValue(hex.charAt(j));
}
if (i % bAll == 0 && i % oAll == 0 && i % dAll == 0 && i % hAll == 0) {
num++;
if (num == 2023) {
System.out.println(i);
break;
}
}
}
*/
}
}
相关知识
public class Main{
public static void main(String[] args) {
//字符串转数字
String str="123";
int s1=Integer.valueOf(str);
int s2=Integer.parseInt(str);
Integer s3=new Integer(str);
System.out.println(s1+1);
System.out.println(s2+1);
System.out.println(s3+1);
//数字转字符串
int a=11;
System.out.println(a+"");
System.out.println(Integer.toString(a));
System.out.println(String.valueOf(a));
StringBuilder strBuild=new StringBuilder();
strBuild.append(a);
System.out.println(strBuild.toString());
//Integer和int可以直接赋值,java会自动拆箱
Integer k1=1234;
int k2=k1;
System.out.println(k2);
int q1=12345;
Integer q2=q1;
System.out.println(q2);
}
}
(by 归忆)