串与真值
本帖最后由 juhugufudu 于 2019-9-30 20:01 编辑public class A {
public static void main(String[] args) {
//串与数值的转换
String s = "3456";
int n = 0;
for(int i = 0;i < s.length();i++) {
n = n*10+s.charAt(i)-'0';
}
System.out.println(n);
//例子:数字黑洞
for(;;) {
System.out.println(n);
char[] cc = (n+"").toCharArray();
java.util.Arrays.sort(cc);
int min = 0;
for(int i = 0;i<cc.length;i++) min = min*10+cc-'0';
int max = 0;
for(int j = cc.length-1;j>=0;j--) max = max*10+cc-'0';
int n2 = max-min;
if(n==n2) break;
n = n2;
}
}
}
页:
[1]