本帖最后由 raikecody 于 2014-5-29 09:20 编辑
- //分享一下我曾经自己写的,没有用完全数学的思想去做,就是通过对字符串的操作来的
复制代码- public class Shuixianhua {
- public static void main(String[] args) {
- for (int x=100; x<1000;x++)
- {
- char num1,num2,num3;
-
- int aa,bb,cc;
-
- Integer num = x;
- String str = num.toString();
- StringBuilder sb = new StringBuilder(str);
-
- num1 = sb.charAt(0);
- num2 = sb.charAt(1);
- num3 = sb.charAt(2);
- aa = Integer.parseInt(num1+"");
- bb = Integer.parseInt(num2+"");
- cc = Integer.parseInt(num3+"");
-
- if (x==aa*aa*aa+bb*bb*bb+cc*cc*cc)
- System.out.println("水仙花:"+x);
- else
- continue;
- }
- }
- }
复制代码
|