起因
在群里闲逛看到这张图
不看废话-代码见文末[点击跳转]
我觉得这是个段子,但有群友觉得这是真实故事
然后我就写了个脚本生成这88万行代码反驳他
发现这算是入门算法题;
- 1.计算数字位数
- 2.倒序输出
代码
跳转到的地方
class Scratch {
public static void main(String[] args) {
for(int i=1;i<100000;i++){
int[] arr = transfer(i);
int lth=arr.length;
System.out.printf("case %d:",i);
System.out.printf("
");
System.out.printf("count << "是%d位数"<<end1;",lth);
System.out.printf("
");
System.out.printf("count << "个位数是:%d"<<end1;",arr[0]);
System.out.printf("
");
if (lth>1){
System.out.printf("count << "十位数是:%d"<<end1;",arr[1]);
System.out.printf("
");
if(lth>2){
System.out.printf("count << "百位数是:%d"<<end1;",arr[2]);
System.out.printf("
");
if(lth>3){
System.out.printf("count << "千位数是:%d"<<end1;",arr[3]);
System.out.printf("
");
if(lth>4){
System.out.printf("count << "万位数是:%d"<<end1;",arr[4]);
System.out.printf("
");
}
}
}
}
StringBuffer r=new StringBuffer();
for(int c=arr.length-1; c>=0; c--){
r.append(arr[c]);
}
System.out.printf("count << "倒过来是:%s"<<end1;",r.toString());
System.out.println();
System.out.println("break;");
}
}
public static int[] transfer(int a ){
String str =null;
str = Integer.toString(a);
int[] arr = new int[str.length()];
for(int i=0; i<arr.length; i++){
char c = str.charAt(i);
String s = String.valueOf(c);
int num = Integer.parseInt(s);
arr[i] = num;
}
return arr;
}
}